Title Description
Write a program that sorts the characters in the input string according to the following rules.
Rule 1: English letters are arranged from A to Z, and are not case sensitive.
For example, input: type output: Epty
Rule 2: When the case of the same English letter exists, it is arranged in the order of entry.
For example, input: BabA output: aABb
Rule 3: Other characters of non-English letters remain in their original position.
For example, input: By?e output: Be?y
Examples:
Input:
A Famous Saying:much Ado About Nothing (2012/8).
Output:
A aaaabc Dfgghh:iimm nNn oooos sttuuuy (2012/8).
Use a vector to record the letters in a string, the outer loop in alphabetical order, and the number of strings within the loop
1#include <iostream>2#include <string>3#include <vector>4 using namespacestd;5 BOOLIsupper (Charch)6 {7 if(Ch >='A'&&ch <='Z'))8 return true;9 ElseTen return false; One } A BOOLIslower (Charch) - { - if(ch>='a'&&ch<='Z') the return true; - Else - return false; - } + - intMain () + { A stringstr; at while(Getline (CIN, str)) - { - intLen =str.size (); -vector<Char>Vec; - for(intI=0;i< -; i++) - { in for(intj=0; j<len;j++) - { to if(str[j]-'a'==i | | str[j]-'A'==i) + Vec.push_back (Str[j]); - } the } * for(intj=0, k=0; J<len&&k<vec.size (); j + +) $ {Panax Notoginseng if(Isupper (str[j]) | |islower (Str[j])) -str[j]=vec[k++]; the } + A the + -cout << str <<Endl; $ } $ return 0; -}
Sort uppercase and lowercase letters at the same time