C++ 输入10个字符串,打印出重复的字符串和重复次数。
2个回答
展开全部
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char ** argv)
{
string s;
vector<string> vlist;
vector<int> nlist;
while(cin>>s)
{
for (int i = 0; i < vlist.size(); ++i)
{
if (vlist.at(i) == s) ++nlist.at(i);
}
if (i == vlist.size())
{
vlist.push_back(s)
nlist.push_back(0);
}
}
for (int i = 0; i < nlist.size(); ++i)
{
if (nlist.at(i))
{
cout<<"重复字符串"<<vlist.at(i)<<endl;
cout<<"重复次数"<<nlist.at(i)<<endl;
}
return 0;
}
#include <vector>
#include <string>
using namespace std;
int main(int argc, char ** argv)
{
string s;
vector<string> vlist;
vector<int> nlist;
while(cin>>s)
{
for (int i = 0; i < vlist.size(); ++i)
{
if (vlist.at(i) == s) ++nlist.at(i);
}
if (i == vlist.size())
{
vlist.push_back(s)
nlist.push_back(0);
}
}
for (int i = 0; i < nlist.size(); ++i)
{
if (nlist.at(i))
{
cout<<"重复字符串"<<vlist.at(i)<<endl;
cout<<"重复次数"<<nlist.at(i)<<endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询