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, ‘\n‘);
        strs.push_back(line);
    }

    int i;
    for (i=0; i<256; i++) {
        char ch = ‘\0‘;
        int j;
        for (j=0; j<n; j++) {
            int len = strs[j].size();
            if (i >= len) break;
            if (j == 0) {
                ch = strs[j][len - i - 1];
                continue;
            }
            if (ch != strs[j][len - i - 1]) break;
        }
        if (j != n) break;
    }
    if (i == 0) {
        cout<<"nai"<<endl;
    } else {
        cout<<strs[0].substr(strs[0].size() - i)<<endl;
    }
    return 0;
}

再水一发

时间: 2024-10-11 06:58:34

PAT 1077 Kuchiguse的相关文章

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 (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

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

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

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

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