2019网易游戏(互娱)秋招,一封奇怪的信
一封奇怪的信
http://www.nowcoder.com/questionTerminal/d7764905e41a413c98900e22a9cc4ec3
/* 使用了STL的map()函数,与其他优秀的同学相比,略显得复杂 */ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> using namespace std; void aStrageLetter() { vector<int> numStr(26); for (int i = 0; i < 26; i++) { cin >> numStr[i]; } string s; getchar(); getline(cin, s); int len = s.length(); map<int, int> mp; for (int i = 0; i < len; i++) { mp[s[i]] = numStr[s[i] - 'a']; } int cnt = 1; int sumLen = 0; for (int i = 0; i < len; i++) { if (sumLen + mp[s[i]] > 100) { cnt++; sumLen = mp[s[i]]; } else { sumLen += mp[s[i]]; } } cout << cnt << " " << sumLen << endl; } int main(){ aStrageLetter(); return 0; }