PAT BASIC 1042

来源:互联网 发布:玻璃厂加工中心编程 编辑:程序博客网 时间:2024/05/29 16:43

思路:

这个题就是个普通的字符串处理的题,不要忘了大小写的处理,没有什么要特殊注意的点。

代码:

#include<iostream>#include<string>using namespace std;int main(){  int len, i, j, max = 0;  int num[26] = { 0 };  string str;  char s;  getline(cin, str);  len = str.size();  for (i = 0; i < len; i++)  {    s = str[i];    if (s >= 'A' && s <= 'Z')    {      num[s - 'A']++;    }    else if (s >= 'a' && s <= 'z')    {      num[s - 'a']++;    }  }  for (i = 0; i < 26; i++)    if (num[i]>max)      max = num[i];  for (i = 0; i < 26;i++)    if (max == num[i])    {      s = i + 'a';      break;    }  cout << s << " " << max;  //while (1)  //{ }  return 0;}
0 0
原创粉丝点击