1077. Kuchiguse (20)

来源:互联网 发布:mac专柜口红价格 编辑:程序博客网 时间:2024/04/29 23:52

1077. Kuchiguse (20)

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming

The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:

  • Itai nyan~ (It hurts, nyan~)
  • Ninjin wa iyada nyan~ (I hate carrots, nyan~)

    Now given a few lines spoken by the same character, can you find her Kuchiguse?

    Input Specification:

    Each input file contains one test case. For each case, the first line is an integer N (2<=N<=100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.

    Output Specification:

    For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write "nai".

    Sample Input 1:
    3Itai nyan~Ninjin wa iyadanyan~uhhh nyan~
    Sample Output 1:
    nyan~
    Sample Input 2:
    3Itai!Ninjinnwaiyada T_TT_T
    Sample Output 2:
    nai
    N条句子
    看是否有标准结尾;有输出标准结尾,否则“nai”
    比如 
          哈哈
          呜呜     
    输出 nai
    比如 
    読书は学问の术なり、学问は事をなすの术なり
    ただ学问を勤めて物事をよく知る者は贵人となり富人となり、无学なる者は贫人となり下人となるなり
  • 输出  なり

    评测结果

    时间结果得分题目语言用时(ms)内存(kB)用户8月16日 22:59答案正确201077C++ (g++ 4.7.2)2308datrilla

    测试点

    测试点结果用时(ms)内存(kB)得分/满分0答案正确118010/101答案正确13081/12答案正确11803/33答案正确23083/34答案正确13083/3
    #include<iostream> #include<vector>  #include<string>using namespace std; int main(){  int N, index, len;  bool Flag;  cin >> N;  getchar();/*吸收换行符*/  vector<string>str(N + 1);  for (index = 1; index <= N; index++)    getline(cin, str[index]);    str[0] = "\0";  Flag = true;  len = 0;  do  {    char ctemp;    len = str[1].size();    if (len > 0)    {       ctemp = str[1][len - 1];         str[1].erase(len - 1, 1);    }    else Flag = false;    for (index = 2; index <= N&&Flag; index++)    {       len = str[index].size();      if (len > 0&& ctemp == str[index][len - 1])         str[index].erase(len - 1, 1);       else Flag = false;    }    if (Flag)str[0] = ctemp + str[0];  } while (Flag);    if (str[0].size() > 0)cout << str[0] << endl;    else cout << "nai" << endl;    system("pause");  return 0;}
    0 0