没时间啦,大家帮帮忙啊!一个由马甲推主ID的程序问题,大家帮忙看看啊!
样例输入8
inkfish 192.168.29.24
zhi 192.168.29.235
magicpig 192.168.50.170
pegasus 192.168.29.235
iamcs 202.116.77.131
finalBob 192.168.29.24
tomek 202.116.77.131
magicduck 192.168.50.170
4
mmmmmm 172.16.72.126
kkkkkk 192.168.49.161
llllll 192.168.49.161
nnnnnn 172.16.72.126
0
样例输出
tomek is the MaJia of iamcs
finalBob is the MaJia of inkfish
magicduck is the MaJia of magicpig
pegasus is the MaJia of zhi
llllll is the MaJia of kkkkkk
nnnnnn is the MaJia of mmmmmm
其中8,4代表有几组测试样例,程序输入0结束,下面是我的程序
程序代码:
#include <stdio.h> #include <string.h> struct DATA { char ID[13]; char IP[16]; char c; } data[20]; struct MJ { char mid[13]; char jid[13]; } mj[10]; char tmp[13]; int n,i,m,k,j; int main(void) { while (1) { scanf("%d",&n); if (n==0) break; for (i=0;i<n;i++) { scanf("%s%s",data[i].ID,data[i].IP); data[i].c=0; } k=0; while (1) { m=-1; for (i=0;i<n;i++) { if (data[i].c==0) { if (m==-1) { data[i].c=1; m=i; } else { if (strcmp(data[m].IP,data[i].IP)==0) { data[i].c=1; strcpy(mj[k].mid,data[m].ID); strcpy(mj[k].jid,data[i].ID); k++; break; } } } } if (i>=n) break; } for (i=0;i<k-1;i++) { for (j=i+1;j<k;j++) { if (strcmp(mj[i].mid,mj[j].mid)==1) { strcpy(tmp,mj[i].mid);strcpy(mj[i].mid,mj[j].mid);strcpy(mj[j].mid,tmp); strcpy(tmp,mj[i].jid);strcpy(mj[i].jid,mj[j].jid);strcpy(mj[j].jid,tmp); } } } for (i=0;i<k;i++) { printf("%s is the MaJia of %s\n",mj[i].jid,mj[i].mid); } printf("\n"); } }我的程序中总是只能测一次,比如第一个输入8,下面输入8组ID,IP后就自动得出结果,也没有遇0结束,大家帮忙看看啊,该怎么改改这个程序?谢谢大家啦!!