提交记录 #202
提交时间:2024-11-12 19:56:49
语言:c
状态:CompileError
编译情况:编译错误
code.c: In function ‘main’:
code.c:8:10: error: ‘i’ undeclared (first use in this function)
8 | str1[i][strcspn(str1[i], "\n")] = '\0';
| ^
code.c:8:10: note: each undeclared identifier is reported only once for each function it appears in
固定测试点暂不可用
附加测试点暂不可用
34【字符】合并字符串
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100],str2[100],result[100];
scanf("%s %s",str1,str2);
str1[i][strcspn(str1[i], "\n")] = '\0';
str2[i][strcspn(str2[i], "\n")] = '\0';
int i=0,j=0,k=0;
int len1=strlen(str1),len2=strlen(str2);
while(i<len1&&j<len2)
{
if(str1[i]<str2[j])
{
result[k++]=str1[i++];
}
else
{
result[k++]=str2[j++];
}
}
while (i < len1)
{
result[k++] = str1[i++];
}
while (j<len2)
{
result[k++] = str2[j++];
}
printf("%s\n",result);
}