baijing @ 2017-03-29 16:50:27
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <map>
using namespace std;
map<string, int> m;
int num[100], cnt = 0;
int ans[100], book[100];
long long minn = 9223372036854775807;
string s;
void DFS(int n)
{
if(n == cnt)
{
// for(int j = 0; j < cnt; j++)
// {
// cout << ans[j] << ' ';
// }
//
// cout << endl;
long long t = 1;
long long sum = 0;
for(int j = cnt - 1; j >= 0; j--)
{
sum += ans[j] * t;
t *= 100;
}
// cout << sum << endl;
if(sum < minn)
{
minn = sum;
}
return;
}
for(int i = 0; i < cnt; i++)
{
if(book[num[i]] == 0)
{
ans[n] = num[i];
book[num[i]] = 1;
DFS(n + 1);
book[num[i]] = 0;
}
}
}
int main()
{
//getline(cin, s);
m["one"] = 1;
m["two"] = 2;
m["three"] = 3;
m["four"] = 4;
m["five"] = 5;
m["six"] = 6;
m["seven"] = 7;
m["eight"] = 8;
m["nine"] = 9;
m["ten"] = 10;
m["eleven"] = 11;
m["twelve"] = 12;
m["thirteen"] = 13;
m["fourteen"] = 14;
m["fifteen"] = 15;
m["sixteen"] = 16;
m["seventeen"] = 17;
m["eighteen"] = 18;
m["nineteen"] = 19;
m["twenty"] = 20;
m["a"] = 1;
m["both"] = 2;
m["another"] = 2;
m["first"] = 1;
m["second"] = 2;
m["third"] = 3;
m["zero"] = 0;
int i = 0, j;
getline(cin, s);
for(i = 0; i < s.length();)
{
for(j = i + 1; j < s.length(); j++)
{
if(s[j] == ' ')
{
//cout << s.substr(i, j - i) << endl;
string tmp = s.substr(i, j - i);
map<string, int>::iterator it = m.find(tmp);
if(it != m.end())
{
num[cnt++] = m[tmp] * m[tmp] % 100;
}
i = j + 1;
break;
}
}
if(s[i] == '.')
{
break;
}
}
DFS(0);
cout << minn << endl;
return 0;
}
by xryjr233 @ 2017-05-21 16:14:58
我也没过。。。不过话说你写那么复杂干嘛。。sort不会吗。。
by wisdom_grass @ 2017-07-08 11:56:12
m["a"] = 1;
m["both"] = 2;
m["another"] = 2;
m["first"] = 1;
m["second"] = 2;
m["third"] = 3;
m["zero"] = 0;
????