问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include<iostream>
#include<string>
using namespace std;
struct Person
{
char name[20];
int count;
};
int main() {
Person leader[3] = { "Li",0,"Zhang",0,"Qin",0 };
int i, j;
char leader_name[20];
for (i = 0; i < 10; i++) {
cin >> leader_name;
for (j = 0; i < 3; j++) {
if (strcmp(leader_name, leader[j].name) == 0)
leader[j].count++;
}
}
cout << endl;
for(i = 0; i < 3; i++) {
cout << leader[i].name << ":" << leader[i].count << endl;
}
return 0;
}