输入字符串,并比较输入频率最大的那个字符串
难点: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; } | |||
|
转载于:.html
本文发布于:2024-02-05 07:47:29,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170727726764659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |