/* one two three four five six seven eight nine zero { 'z' is distinct }[\zero] one two three four five six seven eight nine {'x' is distinct }[\six] one two three four five seven eight nine {'s' is distinct }[\seven] one two three four five eight nine { 'v' is distinct }[\five] one two three four eight nine {'f' is distinct}[\four] one two three eight nine {'w' is distinct}[\two] one three eight nine {'g' is distinct}[\eight] one three nine { 'o' is distinct }[\one] three nine {'i' is distinct}[\nine] three {'r' is distinct}*/
无while解决
因为解必存在,可以用贪心的思想。
发现英文的单词0~9有各自的特点
因此我们首先保存记录每个字符
然后一步一步的取出每个数字的特征字母。
当然比如你算zero,取出zero中的z的时候,别忘了把下层的天特征字母r,o减去相应的值比如
然后用可以很轻松无while解决了。
这一堆while看得我眼花缭乱,自己的代码好丑啊!
你甚至可以考虑递归版本……
//simple test of the discussion zone
//the idea is to find out all the number from the input according to a SPECIAL order
include
include
include
include
include
using namespace std;
int main()
{
int cse;
cin>>cse;
for(int p=0;p result; memset(table,0,sizeof(table)); string s; cin>>s;
for(int i=0;i<s.length();i++){
table[s[i]]++;
}
// find 0
int t=table[‘Z’];
for(int i=0;i<t;i++){
table[‘Z’]–;
table[‘E’]–;
table[‘R’]–;
table[‘O’]–;
result.push_back(0);
}
// find 6
t=table[‘X’];
for(int i=0;i<t;i++){
table[‘S’]–;
table[‘I’]–;
table[‘X’]–;
result.push_back(6);
}
// find 8
t=table[‘G’];
for(int i=0;i<t;i++){
table[‘E’]–;
table[‘I’]–;
table[‘G’]–;
table[‘H’]–;
table[‘T’]–;
result.push_back(8);
}
// find 7
t=table[‘S’];
for(int i=0;i<t;i++){
table[‘S’]–;
table[‘E’]–;
table[‘V’]–;
table[‘E’]–;
table[‘N’]–;
result.push_back(7);
}
// find 5
t=table[‘V’];
for(int i=0;i<t;i++){
table[‘F’]–;
table[‘I’]–;
table[‘V’]–;
table[‘E’]–;
result.push_back(5);
}
// find 4
t=table[‘F’];
for(int i=0;i<t;i++){
table[‘F’]–;
table[‘O’]–;
table[‘u’]–;
table[‘R’]–;
result.push_back(4);
}
// find 2
t=table[‘W’];
for(int i=0;i<t;i++){
table[‘T’]–;
table[‘W’]–;
table[‘O’]–;
result.push_back(2);
}
// find 3
t=table[‘T’];
for(int i=0;i<t;i++){
table[‘T’]–;
table[‘H’]–;
table[‘R’]–;
table[‘E’]–;
table[‘E’]–;
result.push_back(3);
}
// find 9
t=table[‘I’];
for(int i=0;i<t;i++){
table[‘N’]–;
table[‘I’]–;
table[‘N’]–;
table[‘E’]–;
result.push_back(9);
}
// find 1
t=table[‘O’];
for(int i=0;i<t;i++){
table[‘O’]–;
table[‘N’]–;
table[‘E’]–;
result.push_back(1);
}
sort(result.begin(),result.end());
cout<<”case #”<<p<<’:’<<endl;
for(int i=0;i<result.size();i++){
cout<<result[i];
}
cout<<endl;
}
}