如题所述
第1个回答 推荐于2016-09-15
#include<iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main()
{
//fstream cin("e:\\1\\1.txt");
map<char,int> cimap;
int line;
cin>>line;
string str;
for(int i = 0; i!=line; ++i)
{
cin>>str;
for(string::iterator it = str.begin(); it!=str.end(); ++it)
{
++cimap[*it];
}
int len = cimap.size();
for(map<char,int>::iterator jt = cimap.begin(); jt!=cimap.end(); ++jt)
{
jt->second==1? cout<<jt->first : cout<<jt->second<<jt->first;
}
cimap.clear();
cout<<'\n';
}
return 0;
}
Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 100.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C本回答被提问者和网友采纳
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main()
{
//fstream cin("e:\\1\\1.txt");
map<char,int> cimap;
int line;
cin>>line;
string str;
for(int i = 0; i!=line; ++i)
{
cin>>str;
for(string::iterator it = str.begin(); it!=str.end(); ++it)
{
++cimap[*it];
}
int len = cimap.size();
for(map<char,int>::iterator jt = cimap.begin(); jt!=cimap.end(); ++jt)
{
jt->second==1? cout<<jt->first : cout<<jt->second<<jt->first;
}
cimap.clear();
cout<<'\n';
}
return 0;
}
Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 100.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C本回答被提问者和网友采纳