1 条题解
-
0
C :
#include<stdio.h> #include<string.h> #include<ctype.h> char s[1000],a[100],b[100],t[100],f[2]; int main(){ gets(s); gets(a); gets(b); int i,j,n = strlen(s),m = strlen(a); for(i=0;i<n;){ memset(t,0,sizeof(t)); for(j=i;j<i+m && j<n;j++){ f[0] = s[j]; f[1] = '\0'; strcat(t,f); } if(strcmp(t,a)==0){ printf("%s",b); i = j; }else{ printf("%c",s[i]); i++; } } return 0; }C++ :
#include <iostream> using namespace std; string check(string a, int index, int size) { size += index; size = size > a.size() ? a.size() : size; string r = ""; // cout << "from: " << index << " to: " << size << endl; for (; index < size; index++) { r += a[index]; } // cout << "get: " << r << endl; return r; } int main() { string msg, a, b; getline(cin, msg); msg += ' '; getline(cin, a); getline(cin, b); string c = ""; for (int i = 0; i < msg.size(); i++) { if (a[0] == msg[i] and check(msg, i, a.size()) == a ) { // cout << "get:" << a << " " << a.size() << endl; c += b; i += a.size() - 1; } else c += msg[i]; } cout << c; }Python :
str1=input() str2=input() str3=input() x=str1.replace(str2,str3) print(x)
- 1
信息
- ID
- 2222
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者