You have a list of computer brands and their price. You need to determine if the price of each brand has the same number of "4" s and "7" s. If this happens, then the name of the brand is returned. Otherwise, "-1" is returned. If there are two or more brands that meet the same condition, you must select the one with the lowest price.
Example:
LENOVO
4747
MAC
48657
Both comply with the condition, but LENOVO is returned because it is of lower price.
Entry: An integer n representing the number of brands to be evaluated, and n brands with their respective prices
Solution attempt:
#include <iostream>
#include <string>
#include <cstring>
#include <conio.h>
#include <stdio.h>
using namespace std;
int n,i;
int main(){
cin>>n;
for(i=0;i<n;i++){
int contador1=0;
int contador2=0;
string m;
string a;
cin>>m;
cin>>a;
int b = a.length();
char _a[b];
strcpy(_a, a.c_str());
for (int k=0; k<b;k++){
if (_a[k]=='4'){
contador1++;
}
else if (_a[k]=='7'){
contador2++;
}
}
if (contador1!=0 && contador2!=0 && contador1==contador2){
cout<<m<<endl;
}
else{
cout<<-1<<endl;
}
}
return 0;
}
The code works well if it's just a brand, but if it's more than one I do not know what to do to compare them in case more than one complies with the condition. How do I assign individuality to each brand to use this code and finally compare them?