提交记录 #347
提交时间:2024-12-02 17:18:44
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:81:5: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
81 | gets(a);
| ^~~~
| fgets
code.c: In function ‘replace’:
code.c:67:18: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | result[i]=a[cnt];
| ~~~~~~~~~^~~~~~~
/usr/bin/ld: /tmp/ccDBCQ5Q.o: in function `main':
code.c:(.text.startup+0x21): warning: the `gets' function is dangerous and should not be used.
固定测试点#1:
固定测试点#2:
固定测试点#3:
额外测试点#1:
52【字符】字符替换*——用指针更方便
#include <stdio.h>
#include <string.h>
void replace (char *a,char *b,char *c)
{
int l1,l2,l3;
l1=strlen(a);
l2=strlen(b);
l3=strlen(c);
char result[101];
int start,s=0;
int test=0;
while(test==0)
{
for(int i=s;i<l1;i++)
{
if(a[i]==b[0])
{
start=i;
}
}
s=start;
int cnt=0,i=s;
int flag=1;
while (cnt<l2)
{
if(a[i]!=b[cnt])
{
flag=0;
}
i++;
cnt++;
}
if(flag==1)
{
start=s;
test=1;
}
else s++;
}
for(int i=0;i<start;i++)
{
result[i]=a[i];
}
int cnt=0;
for(int i=start;i<start+l3;i++)
{
result[i]=c[cnt];
cnt++;
}
cnt=start+l2;
for(int i=start+l3;i<l1-l2+l3;i++)
{
result[i]=a[cnt];
cnt++;
}
result[l1-l2+l3]='\0';
puts(result);
}
int main()
{
char a[100],b[10],c[10];
gets(a);
gets(b);
gets(c);
replace(a,b,c);
return 0;
}