#include<stdio.h>#include<stdlib.h>
int Judge(char p[],char *q);
void AAA(char *a,char *b);
int main()
{
int i = 0;
int max = 0;
char s[1024];
char copy[1024];
char end[1024] = "***end***";
while(scanf("%s",&s) != 0 )
{
if(Judge(s,end) != 1)
AAA(copy,s);
else
break;
for(i = 0;s[i] != '\0';i++) ;
i > max ? max = i : max = max;
}
if(max != 0)
{
printf("%d\n",max - 1);
for(i = 0;i < max;i++)
printf("%c",copy[i]);
}
system("pause");
return 0;
}
int Judge(char p[],char *q)
{
int i = 0;
int count = 0;
for(i = 0;i < 9;i++)
{
if(p[i] == *(q+i))
count ++;
}
if(count == 9)
return 1;
return 0;
}
void AAA(char *a,char *b)
{
int i = 0;
for(i = 0;*(b + i) != '\0';i++)
{
*(a + i) = *(b + i);
}
}
每次输出 只会输出最后一个空格后的一部分
比如 输入 abs 213jd
输出 213jd
改成这样:
while(*b !='\0')
{
*a ++ = *b ++;
}
#include<stdio.h>
#include<stdlib.h>
int Judge(char p[],char *q);
void AAA(char *a,char *b);
int main()
{
int i = 0;
int max = 0;
char s[1024];
char copy[1024];
char end[1024] = "***end***";
while(scanf("%s",&s) != 0 )
{
if(Judge(s,end) != 1)
AAA(copy,s);
else
break;
for(i = 0;s[i] != '\0';i++) ;
i > max ? (max = i): (max = max);
}
if(max != 0)
{
printf("%d\n",max);
printf("%s",copy);
}
system("pause");
return 0;
}
int Judge(char p[],char *q)
{
int i = 0;
int count = 0;
for(i = 0;i < 9;i++)
{
if(p[i] == *(q+i))
count ++;
}
if(count == 9)
return 1;
return 0;
}
void AAA(char *a,char *b)
{
int i = 0;
for(i = 0;*(b + i) != '\0';i++)
{
*(a + i) = *(b + i);
}
*(a+i)='\0';
}
亲,你的代码写的质量有待提高啊,加油!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int Judge(char p[],char *q);
void AAA(char *a,char *b);
int main()
{
int i = 0;
int max = 0;
char s[1024] = {0};
char copy[1024] = {0};
char end[1024] = "***end***";
while(scanf("%s",&s) != 0 )
{
if(Judge(s,end) != 1)
AAA(copy,s);
else
break;
for(i = 0;s[i] != '\0';i++) ;
i > max ? max = i : max = max;
}
if(max != 0)
{
printf("%d\n",max - 1);
for(i = 0;i < max;i++)
printf("%c",copy[i]);
}
system("pause");
return 0;
}
int Judge(char p[],char *q)
{
int i = 0;
int count = 0;
for(i = 0;i < 9;i++)
{
if(p[i] == *(q+i))
count ++;
}
if(count == 9)
return 1;
return 0;
}
void AAA(char *a,char *b)
{
int i = 0;
int start = strlen(a); // 这里要从后面开始追加字符,而不是直接从0开始覆盖。
for(i = 0;*(b + i) != '\0';i++)
{
*(a + start+ i) = *(b + i);
}
}本回答被网友采纳