[CODE]#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
//select the letters of input the store them in a string
char word;
string str;
while ((word = cin.get()) != '\n'){
if (isalpha(word)){
word = tolower(word);
str += word;
}
}
//insertion sort for the string
for (int i = 1;i < str.size();++i){
if (str[i] < str[i-1]){
char temp = str[i];
int j = i;
do{
str[j] = str[j-1];
--j;
}
while (j > 0 && temp < str[j-1]);
str[j] = temp;
}
}
if (str.empty()){
cerr << "no letter in your input" << endl;
system("pause");
return EXIT_FAILURE;
}
cout << str << endl;
//count the letter times
int pos = 0;
while (true){
char key = str[pos];
int mark = str.find_first_not_of(key,pos);
if (mark == string::npos){
cout << key << "\t\t" << str.size() - pos << endl;
break;
}
int length = mark - pos;
cout << key << "\t\t" << length << endl;
pos = mark;
}
system("PAUSE");
return EXIT_SUCCESS;
}
[/CODE]
不知道符合要求不
N久前写的,可以接受任何形式的输入,回车键结束。