1077. Kuchiguse

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:

3
Itai nyan~
Ninjin wa iyadanyan~
uhhh nyan~

Sample Output 1:

nyan~

Sample Input 2:

3
Itai!
Ninjinnwaiyada T_T
T_T

Sample Output 2:

nai
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5
 6 int main()
 7 {
 8     int n, i, j, k = 0;
 9     char str[110][300];
10     scanf("%d", &n);
11     getchar();
12     int len, minlen = 300;
13     for(i = 0; i < n; i++)
14     {
15         gets(str[i]);
16         len = strlen(str[i]);
17         if(len < minlen)
18         {
19             minlen = len;
20         }
21         for(j = 0; j < len / 2; j++)
22         {
23             char temp = str[i][j];
24             str[i][j] = str[i][len - 1 - j];
25             str[i][len - 1 - j] = temp;
26         }
27     }
28     for(j = 0; j < minlen; j++)
29     {
30         int flag = 1;
31         char temp = str[0][j];
32         for(i = 0; i < n; i++)
33         {
34             if(str[i][j] != temp)
35             {
36                 flag = 0;
37                 break;
38             }
39         }
40         if(flag)
41             k++;
42         else
43             break;
44     }
45     if(k <= 0)
46         printf("nai\n");
47     else
48     {
49         for(j = k - 1; j >= 0; j--)
50         {
51             printf("%c", str[0][j]);
52         }
53         printf("\n");
54     }
55     return 0;
56
57 }
时间: 2024-11-28 23:34:02

1077. Kuchiguse的相关文章

1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B 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 prefere

pat 1077 Kuchiguse(20 分) (字典树)

1077 Kuchiguse(20 分) 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

1077 Kuchiguse (20 分)求字符串最长相同后缀

1077 Kuchiguse (20 分) 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 ofte

1077 Kuchiguse (20 分)

1077 Kuchiguse (20 分) 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 ofte

1077. Kuchiguse (20)

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 artistic

PAT 1077 Kuchiguse (20)

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 artistic

[PAT] 1077 Kuchiguse (20 分)Java

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 artistic

PAT (Advanced Level) 1077. Kuchiguse (20)

最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; char s[200][300];

PAT 1077 Kuchiguse

#include <iostream> #include <cstdlib> #include <vector> #include <string> using namespace std; int main() { int n = 0; cin>>n; getchar(); vector<string> strs; for (int i=0; i<n; i++) { string line; getline(cin, line