杭电1004
输入字符串,并比较输入频率最大的那个字符串
难点:1.字符串的比较 可以用strcmp(a,b),若相等,则返回的是0,若不等,返回1!别弄错咯
#include<iostream> using namespace std; int main( ) { int round; cin >> round; while (round) { char ballo[1001][16]; int fre[1001] = { 0}; char tem[15]; int m = 0, n = 0; int count = 0; for (int i = 0; i < round; i++) { cin >> tem; int j = 0; while (j != i && strcmp(tem,ballo[j])) { j++; } if (!strcmp(tem,ballo[j])) fre[j]++; else { strcpy_s(ballo[j], tem); fre[j]++; count++; } } int max = fre[0]; int pos = 0; for (int u = 0; u < count; u++) { if (fre[u]>max) { max = fre[u]; pos = u; } } cout << ballo[pos]<<endl; cin >> round; } return 0; } |
|||
|
浙公网安备 33010602011771号