PAT 1077

簡單題,用C++寫了...

需要注意的是,cin了之後不會把\n吃掉,需要再getchar一次才能夠吃掉\n,然後接着geline才正確

感覺沒什麼美感...

 1 #include <vector>
 2 #include <iostream>
 3 #include <string>
 4 #include <algorithm>
 5 #include <limits>
 6 #include <cstdio>
 7
 8 using namespace std;
 9
10 int main(){
11     int N;
12     cin >> N;
13     getchar();
14
15     vector<string> lines;
16     int shortest = 0x7fffffff;
17     for (int i = 0; i < N; i++){
18         string str;
19         getline(cin, str);
20
21         if (str.size() < shortest)
22             shortest = str.size();
23
24         lines.push_back(str);
25     }
26
27     int common_len = 0;
28     for (int i = 0; i < shortest; i++){
29         char ch = lines[0][lines[0].size() - i - 1];
30
31         int cnt = 1;
32         for (int j = 1; j < lines.size(); j++){
33             string cur_str = lines[j];
34             if (cur_str[cur_str.size() - i - 1] != ch)
35                 break;
36             cnt++;
37         }
38
39         if (cnt == lines.size())
40             common_len++;
41         else
42             break;
43     }
44
45     if (common_len == 0)
46         cout << "nai" << endl;
47     else{
48         string res = lines[0].substr(lines[0].size() - common_len, lines[0].size());
49         cout << res << endl;
50     }
51
52     return 0;
53 }
时间: 2024-10-13 20:02:55

PAT 1077的相关文章

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

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

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考试1077~1080(2014上机复试题目)

题目地址:点击打开链接 还是太弱. . 英文太差.,, 预计要等待被虐了.. 1077 找最长的公共后缀,暴力就能够写: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; char a[105][1005]; int milen;

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 Basic 1077

1077 互评成绩计算 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为 G?1??:老师给这个组的评分记为 G?2??.该组得分为 (G?1??+G?2??)/2,最后结果四舍五入后保留整数分.本题就要求你写个程序帮助老师计算每个组的互评成绩. 输入格式: 输入第一行给出两个正整数 N(> 3)和 M,分别是分组数和满分,均不超过 10

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 (20)-找相同后缀

#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> using namespace std; /* 找最长相同后缀 */ const int maxn=105; char str[maxn][300]; char ans[300]; int len[maxn]; int main() { int n; int