请问下面代码中为什么多一个输出语句程序是对的,去掉就不可以运行了呢?
一定和输入缓存区有关系么?加一个fflush也可以,就是不知道为什么???
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
long int sum,tsum,tnum;
struct word
{
char str[105];
int num;
} A[2][10005];
void chuli(char s[],int k)
{
int i,j,flag=0;
for(i=0; i<=sum; i++)
{
if(strcmp(A[k][i].str,s)==0)
{
A[k][i].num++;
flag=1;
sum++;
}
}
if(flag==0)
{
for(j=0; j<105; j++)
A[k][sum].str[j]=s[j];
A[k][sum].num++;
sum++;
if(k==0)tnum++;
else tsum++;
}
}
void paixu2()
{
int i,j;
char c[105];
struct word a;
for(i=0; i<sum; i++)
{
for(j=i+1; j<sum; j++)
if(A[1][i].num<A[1][j].num)
{
a=A[1][j];
A[1][j]=A[1][i];
A[1][i]=a;
}
else if(A[1][i].num==A[1][j].num&&strcmp(A[1][i].str,A[1][j].str)>0)
{
strcpy(c,A[1][j].str);
strcpy(A[1][j].str,A[1][i].str);
strcpy(A[1][i].str,c);
}
}
}
void chong()
{
int i,j;
for(i=0; i<tsum; i++)
{
for(j=0; j<tnum; j++)
{
if(strcmp(A[0][j].str,A[1][i].str)==0)A[1][i].num=0;
}
}
}
void input2(int k)
{
char ch,s[105]= {'\0'};
int i;
sum=0;
for(i=0; i<10005; i++)
A[k][i].num=0;
scanf("%*s%*c");
while(ch!=-1&&ch!='<')
{
for(i=0; i<105; i++)s[i]='\0';
ch=getchar();
if(ch>='A'&&ch<='Z')ch+=32;
if((65<=ch&&ch<=90)||(ch>=97&&ch<=122))
{
for(i=0;; i++)
{
s[i]=ch;
ch=getchar();
if(ch>='A'&&ch<='Z')ch+=32;
if((65<=ch&&ch<=90)||(ch>=97&&ch<=122))continue;
else break;
}
chuli(s,k);
}
}
scanf("%*s%*c");
if(k==1)
{
chong();
paixu2();
}
}
int main()
{
int n,i;
scanf("%d%*c",&n);
while(n--)
{
for(i=0; i<10005; i++)
for(int k=0; k<2; k++)
memset(A[k][i].str,'\0',sizeof(A[k][i].str));
tnum=0,tsum=0,sum=0;
input2(0);
//fflush(stdin);
printf("****\n");/*********这个输出一定要有,并且不可以什么也不输出,不懂为什么*/
input2(1);
for(i=0; i<tsum&&i<10; i++)
{
if(A[1][i].num==0)continue;
printf("%s\n",A[1][i].str);
}
//fflush(stdin);
if(n!=0)printf("\n");
}
return 0;
}
********下面是测试数据***********
* **** Sample Input****
2
<oldwords>
how aRe you
</oldwords>
<article>
--How old are you?
--Twenty.
</article>
<oldwords>
google cn huluobo net i
</oldwords>
<article>
文章内容:
I love google,dropbox,firefox very much.
Everyday I open my computer , open firefox , and enjoy surfing on the inter-
net.
But these days it's strange that searching "huluobo" is unavail-
able.
What's wrong with "huluobo"?
</article>
* ******Sample Output******
old
twenty
firefox
open
s
able
and
but
computer
days
dropbox
enjoy