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; }
相关文章推荐
- Project Euler Problem 22
- project euler problem 22对文件的处理
- project euler Problem 34
- project euler Problem 56
- project euler Problem 15
- Project Euler Problem 21 Amicable numbers
- Project Euler Problem 36 Double-base palindromes
- http://projecteuler.net/problem=21 [Answer:31626]
- http://projecteuler.net/problem=32 [Answer:45228]
- http://projecteuler.net/problem=35 [Answer:55]
- http://projecteuler.net/problem=38 [Answer:932718654]
- projecteuler Problem 20
- project Eulert 学习笔记 之 problem 22
- Project Euler Problem 16
- Project Euler Problem 15
- project euler problem 10:Summation of primes
- project euler problem 25 大数连加Fibonacci序列
- project euler problem 28
- Project Euler Problem 17
- Project Euler problem 7