Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
还是过不了,不知是否是理解错了,还是输入的问题,请帮忙看看或者发代码来帮忙#include "iostream" #include "string" using namespace std; int main() { //freopen("s.txt","r",stdin); int t; int p,w; int i,temp; unsigned long sum; string s; cin >> t; while (t--) { cin >> p >> w; cin.get(); getline(cin, s); sum = 0; for (i=0; i<s.length(); i++) { if (s[i] >= 'A' && s[i] <= 'C') { temp = s[i]-'A'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'A' && s[i+1] <= 'C') sum += w; } else if (s[i] >= 'D' && s[i] <= 'F') { temp = s[i]-'D'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'D' && s[i+1] <= 'F') sum += w; } else if (s[i] >= 'G' && s[i] <= 'I') { temp = s[i]-'G'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'G' && s[i+1] <= 'I') sum += w; } else if (s[i] >= 'J' && s[i] <= 'L') { temp = s[i]-'J'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'J' && s[i+1] <= 'L') sum += w; } else if (s[i] >= 'M' && s[i] <= 'O') { temp = s[i]-'M'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'M' && s[i+1] <= 'O') sum += w; } else if (s[i] >= 'P' && s[i] <= 'S') { temp = s[i]-'P'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'P' && s[i+1] <= 'S') sum += w; } else if (s[i] >= 'T' && s[i] <= 'V') { temp = s[i]-'T'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'T' && s[i+1] <= 'V') sum += w; } else if (s[i] >= 'W' && s[i] <= 'Z') { temp = s[i]-'W'+1; sum += (temp*p); if (i == s.length()-1) break; if (s[i+1] >= 'W' && s[i+1] <= 'Z') sum += w; } else { sum += p; if (i == s.length()-1) break; if (s[i+1] == ' ') sum += w; } } cout << sum << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator