1 条题解
-
0
C :
#include <stdio.h> #include <string.h> int main() { char str[200]; while(gets(str)) { char ch1[10] = "think"; char ch2[10] = "different"; int len = strlen(str); int f = 0; for(int i = 0; i < len; i++) { if(str[i]==' '&& i>4 && i+9<len) { int k = 0; for(int j = i-5; j < i; j++) { if(str[j]==ch1[k]||str[j]+32==ch1[k]) k++; } if(k==5) { k = 0; for(int j = i+1; j <= i+9; j++) { if(str[j]==ch2[k]||str[j]+32==ch2[k]) k++; } } if(k==9) f++; } } printf("%d\n", f); } }
C++ :
#include <iostream> #include <string> using namespace std; int main() { string s, sub, t = "think different"; int i, ans; while (getline(cin, s)) { for (i = 0; i < s.length(); i++) if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; for (ans = i = 0; i < s.length(); i++) { if (i + 14 < s.length()) { sub = s.substr(i, 15); if (sub == t) ans++; } } cout << ans << endl; } return 0; }
- 1
信息
- ID
- 1956
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者