您的位置:首页 > 其它

Project Euler problem 22

2012-11-04 01:38 344 查看
这又是个模拟题。

哎。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <map>
#include <ctime>
#define MAXN 111111
#define INF 100000007
using namespace std;
struct node
{
string name;
int val;
}p[55555];
string s;
bool cmp(node x, node y)
{
return x.name < y.name;
}
int main()
{
freopen("C:/Users/Administrator/Desktop/data/names.txt", "r", stdin);
cin >> s;
int len = s.length();
int cnt = 0;
string tmp;
for(int i = 0; i < len; i++)
{
if(s[i] < 'A' || s[i] > 'Z')
{
if(tmp.length() == 0) continue;
int k = tmp.length();
int val = 0;
for(int j = 0; j < k; j++)
val += tmp[j] - 'A' + 1;
p[cnt].val = val;
p[cnt].name = tmp;
cnt++;
tmp = "";
}
else tmp += s[i];
}
sort(p, p + cnt, cmp);
long long sum = 0;
for(int i = 0; i < cnt; i++)
sum += (i + 1) * p[i].val;
cout << sum << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: