题目比较简单,输入需要读取一整行,
吐槽一下vc6.0,读取一整行竟然要按两次回车才能输入进去。
代码如下:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
string str;
int main()
{
getline(cin,str);
vector<string> res;
int i;
for(i = 0;i<str.size();i++)
{
string temp = "";
while((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= '0' && str[i] <= '9')
|| (str[i] >= 'A' && str[i] <= 'Z'))
{
if(str[i] >= 'A' && str[i] <= 'Z')
{
str[i] = str[i] - 'A' + 'a';
}
temp += str[i];
i++;
}
if(temp.size() > 0)
res.push_back(temp);
}
sort(res.begin(),res.end());
int max = 0;
int k = 0;
for(i = 0;i<res.size();i++)
{
int j = 1;
while((i+j) < res.size() &&res[i] == res[i+j]){
j++;
}
if(j > max)
{
max= j;
k = i;
}
i = i+j-1;
}
cout << res[k] << " " << max << endl;
return 0;
}
本文详细介绍了使用C++在VC6.0中读取一整行文本时遇到的问题及解决方案,通过代码实例展示了如何正确地处理输入字符串,确保程序能够高效且准确地获取完整信息。
1万+

被折叠的 条评论
为什么被折叠?



