LA 6805 Pantun Grader (simulation)

Source: Internet
Author: User

LA 6805 Pantun Grader (simulation)

6805-Pantun Grader


Question:

Scores poetry based on the given rules. Includes rules such as syllables and rhymes.


Solution:

Carefully read the question and topic details. The entered comma is not necessarily followed by spaces.


Reference code:

#include 
 
  #include #include 
  
   #include 
   
    #include 
    
     using namespace std;const int MAXN = 210;vector
     
       > 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
      
        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;}
      
     
    
   
  
 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.