1.打表
2.搜索并转换
3.排序
4.全排列所有组合
5.比较出最小值
6.输出
#include <iostream>
#include <algorithm>
using namespace std;
int trans(string s)
{
long long ret = 0;
for(int i = s.length(), ps = 10; i >= 0; i--, ps *= 10)
{
ret += ( (s[i] - '0') * ps ) / 10;
}
ret *= ret;
ret %= 100;
return ret;
}
int main()
{
string rstr[22] = {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
string ustr[4] ={"","a","both","another"};
string tstr[4] = {"","first","second","third"};
string txt;
int narr[10] = {0};
int flag = 0;
int tf = 0;
while(cin>>txt && txt != ".")
{
if(txt != "0")
{
for(int i = 0; i < 22; i++)
{
if(rstr[i] == txt)
{
narr[tf++] = (i * i) % 100;
goto quit;
}
}
for(int i = 0; i < 4; i++)
{
if(ustr[i] == txt)
{
narr[tf++] = (i * i) % 100;
goto quit;
}
}
for(int i = 0; i < 4; i++)
{
if(tstr[i] == txt)
{
narr[tf++] = (i * i) % 100;
goto quit;
}
}
}
quit:;
}
sort(narr, narr + tf);
/*for(int i = 0; i < tf; i++)
cout<<narr[i]<<' ';*/
long long ans = 9999999999999;
do
{
long long tans = 0;
long long ps = 10;
for(int i = 0; i < tf; i++)
{
int tmp = narr[i];
tans += ( (tmp % 10) * ps ) / 10;
ps *= 10;
tans += ( ( (tmp / 10) % 10) * ps ) / 10;
ps *= 10;
//cout<<tans<<endl;
}
ans = min(ans, tans);
}while(next_permutation(narr, narr + tf));
cout<<ans<<endl;
return 0;
}