题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4730
2 ohayougozaimasu daijyoubudesu
Case #1: ohayougozaimasunanodesu Case #2: daijyoubunanodesu
代码如下:
string
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> using namespace std; string s, s1, s2; int main() { int t; int cas = 0; cin >> t; while(t--) { printf("Case #%d: ",++cas); cin >> s; int len = s.length(); if(len < 4) { cout<<s<<"nanodesu"<<endl; continue; } s1 = s.substr(len-4,4); s2 = s.substr(0,len-4); if(s1 == "desu") { cout<<s2<<"nanodesu"<<endl; } else { cout<<s<<"nanodesu"<<endl; } } return 0; } /* 99 aa bb ohayougozaimasu daijyoubudesu desu desudesu ddddd */
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; char s[117],s1[117]; int main() { int t; int cas = 0; scanf("%d",&t); while(t--) { scanf("%s",s); int len = strlen(s); for(int i = 0; i < len-4; i++) { s1[i] = s[i]; } s1[len-4] = '\0'; printf("Case #%d: ",++cas); if(s[len-4]=='d'&&s[len-3]=='e'&&s[len-2]=='s'&&s[len-1]=='u') { //if(len != 4) printf("%s",s1); printf("nanodesu\n"); } else { printf("%s",s); printf("nanodesu\n"); } } return 0; }