ps( Forgive my poor English .....Bear with the dermination of a study of slag.....)
Today , I participate in the 2013 ACM/ICPC Asia Regional Chengdu Online !
I just worked out two problems ------the 1003 and the 1010 . Just as you konw, they are the simple problems.
the details about the problem are followed.
We Love MOE Girls
Problem Description
Chikami Nanako is a girl living in many different parallel worlds. In this problem we talk about one of them.
In this world, Nanako has a special habit. When talking with others, she always ends each sentence with "nanodesu".
There are two situations:
If a sentence ends with "desu", she changes "desu" into "nanodesu", e.g. for "iloveyoudesu", she will say "iloveyounanodesu". Otherwise, she just add "nanodesu" to the end of the original sentence.
Given an original sentence, what will it sound like aften spoken by Nanako?
Input
The first line has a number T (T <= 1000) , indicating the number of test cases.
For each test case, the only line contains a string s, which is the original sentence.
The length of sentence s will not exceed 100, and the sentence contains lowercase letters from a to z only.
Output
For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1. Then output which Nanako will say.
My code:
#include <stdio.h>
#include <string.h>
int main()
{
const int size = 120;
int t,len,i,j;
char word[ size ];
char s[5];
const char ch[] = "nanodesu"; //将要添加的字尾
scanf("%d",&t);
for(int k=0;k<t;k++)
{
scanf("%s",word);
len = strlen(word);
memset(s,0,sizeof(s));
if(len>=4) //如果字元串長度大于4才需要判斷desu;
{
for(i=len-4,j=0;i<len;i++,j++)
s[j]=word[i];
s[5] = '\0';
}
if(!strcmp("desu",s))
{
strcpy(word+len-4,ch);
}
else strcat(word,ch);
printf("Case #%d: %s\n",k+1,word);
}
}
0Ms pass.