UVaLive/LA 6805 Pantun Grader(模拟)
2014-11-23 21:12
344 查看
![]() | 6805 - Pantun Grader |
按照给定的规则,给诗歌打分。有音节、押韵等规则。
解题思路:
仔细读题,主题细节。输入的逗号后不一定有空格。
参考代码:
#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <vector> using namespace std; const int MAXN = 210; vector<vector<string> > sentence; int nCase, cCase; void init() { sentence.clear(); } int calcSyllable(string word) { int len = word.length(); if (len == 6 && (word.find("ng") != string::npos || word.find("Ng") != string::npos || word.find("ny") != string::npos || word.find("Ny") != string::npos)) return 2; if (len == 3 && (word[0] == 'a' || word[0] == 'A' || word[0] == 'e' || word[0] == 'E' || word[0] == 'i' || word[0] == 'I' || word[0] == 'o' || word[0] == 'O' || word[0] == 'u' || word[0] == 'U')) return 2; if (len >= 6) return 3; if (len == 4 || len == 5) return 2; if (len <= 3) return 1; } void solve() { int syllable[MAXN] = {0}, A = 0, B = 0, C = 0, D = 0, E = 0; string last[MAXN]; int n = min(4, (int)sentence.size()); for (int i = 0; i < n; i++) { for (int j = 0; j < sentence[i].size(); j++) { syllable[i] += calcSyllable(sentence[i][j]); if (j == (int)sentence[i].size() - 1) { last[i] = sentence[i][j].substr(sentence[i][j].size() - 2); } } if (syllable[i] >= 8 && syllable[i] <= 12) A += 10; } for (int i = 0; i < n - 2; i++) { if (last[i] == last[i + 2]) B += 20; } for (int i = 0; i < n - 2; i++) { if (syllable[i] == syllable[i + 2]) C += 10; } if (sentence.size() > 4) { D = ((int)sentence.size() - 4) * 10; } E = A + B + C - D; printf("Case #%d: %d %d %d %d %d\n", ++cCase, A, B, C, D, E); } int main() { scanf("%d", &nCase); while (nCase--) { init(); bool flag = false; string tmp; while (true) { string str; vector<string> ss; if (flag) { ss.push_back(tmp); flag = false; } while (cin >> str && str[str.length() - 1] != ',' && str[str.length() - 1] != '.') { if (str.find(',') != string::npos) { int pos = str.find_first_of(','); ss.push_back(str.substr(0, pos)); sentence.push_back(ss); tmp = str.substr(pos+1); flag = true; break; } ss.push_back(str); } if (flag) continue; if (str != "." && str != ",") ss.push_back(str.substr(0, str.length() - 1)); if (str[str.length() - 1] == '.') { sentence.push_back(ss); solve(); break; } if (str[str.length() - 1] == ',') { sentence.push_back(ss); } } } return 0; }
相关文章推荐
- UVaLive 6805 Pantun Grader (恶心的模拟)
- UVALive 3971 Assemble(模拟 + 二分)
- UValive 7269 (模拟)
- UVALive 5873 - Tree Inspections 【模拟】
- UVALive 5963 (LA 5963) Confusion in the Problem Set 二分图匹配 (或 YY)
- UVALive 7327 Digit Division (模拟)
- UVALive 4723 水模拟
- POJ1218 HDU1337 ZOJ1350 UVALive2557 THE DRUNK JAILER【模拟】
- UVALive(LA) 3644 X-Plosives (并查集)
- UVALive 3907 (LA 3907) Puzzle AC自动机 + 搜索DP 记录路径
- UVALive7263-Today Is a Rainy Day(2015ICPC北京C题)-模拟+BFS
- UVALive 6833 (模拟 水~)
- UVALive - 7511 Multiplication Table (模拟)
- UVALive 7512 November 11th(模拟, 思维)
- UVALive - 7000 Present Problem 简单模拟
- uva - 10716 - Evil Straw Warts Live(贪心、模拟)
- UVALive(LA) 3644 X-Plosives (并查集)
- UVALive 4513 (LA 4513) Stammering Aliens 后缀数组 或 hash
- UVaLive ( LA ) 3516 - Exploring Pyramids (DP 递推)
- Dome of Tuxville [UVALive 3347] 模拟退火