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 <bits/stdc++.h> using namespace std; int main(){ char a[100],b[100],c[100]; int s=0,n=0,x=0; bool f=false; gets(a); gets(b); gets(c); for(int i=0;b[i]!='\0';i++){ s++; } for(int i=0;c[i]!='\0';i++){ n++; } for(int i=0;a[i]!='\0';i++){ x++; } for(int i=0;a[i]!='\0';i++){ for(int j=0;j<s&&i<=x-s;j++){ if(a[i+j]!=b[j]){ f=true; break; } } if(f==false&&i<=x-s){ cout<<c; i+=s-1; } else{ cout<<a[i]; } f=false; } return 0; }Java :
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String scanStr=scanner.nextLine(); String replaceQStr=scanner.nextLine(); String replaceHStr=scanner.nextLine(); String newStr=scanStr.replace(replaceQStr,replaceHStr); System.out.println(newStr); } }Python :
str1=input() str2=input() str3=input() x=str1.replace(str2,str3) print(x)
- 1
信息
- ID
- 107
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者