经典指数          
原因
1021
浏览数
0
收藏数
 

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? 输入描述: Each input file contains one test case. For each case, the first line is an integer N (2 输出描述: 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". 输入例子: 3 Itai nyan~ Ninjin wa iyadanyan~ uhhh nyan~ 输出例子: nyan~

     举报   纠错  
 
切换
1 个答案

#include

#include

#include

#include

using namespace std;

int main()

{

    string s="";

    int i,j;

    int n;

    int k;

    char input[1000][1000];

scanf("%d",&n);

getchar();

for(i=0;i

{

      gets(input[i]);

}

for(i=strlen(input[0])-1,j=strlen(input[1])-1;i>=0&&j>=0;i--,j--)

{

        if(input[0][i]==input[1][j])

        {

            s+=input[0][i];

        }

        else

            break;

}

for(i=2;i

{

    string temp=s;

    s="";

 

for(j=strlen(input[i])-1,k=0;j>=0&&k

  {

     if(temp[k]!=input[i][j])

     {

         break;

     }

     else

    {

        s+=input[i][j];

    }

  }

}

if(s.size()==0)

{

        cout<<"nai"<

}

else

{

    for(i=s.size()-1;i>=0;i--)

        printf("%c",s[i]);

  printf("\n");

}

}

 
切换
撰写答案
扫描后移动端查看本题