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
解题思路:英语差是硬伤啊,做成了求最长公共字串,结果发现只是求最长的末尾后缀。
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
for (int n; cin >> n;){
vector<string>vec(n);
//读取换行
getline(cin, vec[0]);
for (int i = 0; i < n; i++){
getline(cin, vec[i]);
reverse(vec[i].begin(), vec[i].end());
}
sort(vec.begin(), vec.end());
string res = "";
int flag = 1;
for (int i = 0; i < vec[0].length(); i++){
for (int j = 1; j < vec.size(); j++){
if (vec[0][i] != vec[j][i]){
flag = 0;
break;
}
}
if (flag){
res += vec[0][i];
}
else{
break;
}
}
if (res.length()){
reverse(res.begin(), res.end());
cout << res << endl;
}
else{
cout << "nai" << endl;
}
}
return 0;
}
本文深入探讨了日本语言中独特的句子结尾粒子「Kuchiguse」及其艺术表现手法,以「nyan~」为例,分析了其作为猫女性格象征的使用方式。通过实例分析,揭示了这种语言现象如何反映说话者的个性,并在动漫与漫画中被夸张运用。文章还提供了一个输入输出样例,展示了如何通过文本分析找出特定角色的「Kuchiguse」。
645

被折叠的 条评论
为什么被折叠?



