题目链接:https://www.luogu.com.cn/problem/P9301
思路:
用一个数组记录改天能来的人数
边读取边记录是否为 “Y” ,若是 “Y” 则该天数能来人数+1
注意,可能会出现不同日期有相同的最大人数
代码如下:
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
int n[5];
memset(n, 0, sizeof(n));
int x, i;
char y;
cin >> x;
while (x--)
{
for (i = 0; i < 5; ++i)
{
cin >> y;
if (y == 'Y')
{
++n[i];
}
}
}
int max = 0, j;
for (i = 0; i < 5; ++i)
{
if (max < n[i])
{
max = n[i];
j = i;
}
}
cout << j + 1;
for (i = j + 1; i < 5; ++i)
{
if (max == n[i])
{
cout << ',' << i + 1;
}
}
return 0;
}