纯C++解法
ZOJ
http://www.nowcoder.com/questionTerminal/7557d470617c464f9200d93acf721471
#include<bits/stdc++.h> using namespace std; map<char,int> mp; char solve[3]={'Z', 'O', 'J'}; int main() { string str; while( cin>>str ) { mp.clear(); for(char c: str ) { mp[c]++; } while( 1 ) { for(int i=0; i<3; ++i) { if( mp[ solve[i] ]>0 ) { cout<<solve[i]; mp[ solve[i] ]--; } } if( ( 0== mp[solve[0]] ) && 0== mp[solve[1]] && 0== mp[solve[2]]) { cout<<endl; break; } } } return 0; }