UVaLive/LA 6805 Pantun Grader(模拟)
来源:互联网 发布:开通淘宝直播 编辑:程序博客网 时间:2024/05/14 10:52
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;}
0 0
- UVaLive/LA 6805 Pantun Grader(模拟)
- Pantun Grader(模拟)
- UVaLive/LA 6801 Sequence(DP)
- UVaLive/LA 6802 Turtle Graphics(水题)
- LA 4329/uvalive 4329 (树状数组)
- UVaLive(LA) 3902 Network,Seoul 2007
- LA 3602 (贪心,模拟)
- UVALive 6833Miscalculation (模拟)
- uvalive 4254(二分+模拟)
- UVALive 7139 Rotation(模拟)
- UVALive 4264 Message (模拟)
- UVALive - 4264 Message (模拟)
- UVALive 3667 Ruler (模拟)
- UVALive 4222 Dance(模拟)
- Appearance Analysis UVALive(模拟)
- UVALive(LA) 3644 X-Plosives (并查集)
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- UVaLive LA 4256 | UVa 1424 - Salesmen(简单DP)
- android网络下载图片并缓存
- 在Java中构建WebSocket应用(基于JSR356)
- pat,1029Median
- Android之获取手机信息
- 大学生实习就业需求调研
- UVaLive/LA 6805 Pantun Grader(模拟)
- 写一个脚本,要求:在画图工具中画一个渐变放大的圆形漩涡效果图。
- Setting property 'source' to 'org.eclipse.jst.jee.server:webProject' did not find a matching propert
- 螺旋方阵
- iOS第三方开源库的吐槽和备忘
- FZU 2104 C - Floor problem
- 黑马程序员——OC---初接触及基本语法
- Matlab与C++混合编程(依赖OpenCV)
- 关于activity的启动模式问题,生命周期和TabActivity是如何做到视图切换的