提交记录 #343
提交时间:2024-12-02 16:37:44
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:54:5: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
54 | gets(a);
| ^~~~
| fgets
code.c: In function ‘replace’:
code.c:40:18: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
40 | result[i]=a[cnt];
| ~~~~~~~~~^~~~~~~
/usr/bin/ld: /tmp/cc8QX0GU.o: in function `main':
code.c:(.text.startup+0x21): warning: the `gets' function is dangerous and should not be used.
固定测试点#1:
固定测试点#2:
固定测试点#3:
额外测试点#2:
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;
for(int i=0;i<l1;i++)
{
if(a[i]==b[0])
{
start=i;
}
}
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;
}