本文主要是介绍长嘘一口气。。。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include "stdio.h"
#include "string.h"const int Len=102;typedef struct
{char name[Len];char value[Len];int flag;
}Keys;Keys oldstr[Len],newstr[Len];int deal(Keys *str)
{int count=0;char ch;int i=0; //i 字母计数指针while(ch!='}'){scanf("%c",&ch);if(ch<='z' && ch>='a')str[count].name[i++]=ch;else if(ch==':')i=0;else if(ch<='9' && ch>='0')str[count].value[i++]=ch;else if(ch==','){i=0;count++;}}return count+1;
}void testprint(Keys *str,int n)
{int i;for(i=0;i<n;i++){printf("%s.",str[i].name);printf("%s ",str[i].value);}printf("\n");
}int main()
{int t;scanf("%d",&t);int i,j;int counto,countn;int sum;while(t--){//initfor(i=0;i<Len;i++){for(j=0;j<Len;j++){oldstr[i].name[j]='\0';oldstr[i].value[j]='\0';newstr[i].name[j]='\0';newstr[i].value[j]='\0';oldstr[i].flag=0; //flag初始化为0,value不变置1,改变置2newstr[i].flag=0;}}counto=deal(oldstr);//testprint(oldstr,counto);countn=deal(newstr);//testprint(newstr,countn);for(i=0;i<counto;i++){for(j=0;j<countn;j++){if(strcmp(oldstr[i].name,newstr[j].name)==0){if(strcmp(oldstr[i].value,newstr[j].value)==0){oldstr[i].flag=1;newstr[j].flag=1;}else{oldstr[i].flag=2;newstr[j].flag=2;}}}}//搜索old串for(i=0;i<counto;i++)if(oldstr[i].flag!=1)break;for(j=0;j<countn;j++)if(newstr[j].flag!=1)break;if(i==counto && j==countn)printf("No changes\n");else//printf("have\n");{sum=0;for(i=0;i<countn;i++){if(newstr[i].flag==0){sum++;if(sum==1)printf("+");printf("%s ",newstr[i].name);}if(sum!=0 && i==countn-1)printf("\n");}sum=0;for(i=0;i<counto;i++){if(oldstr[i].flag==0){sum++;if(sum==1)printf("-");printf("%s ",oldstr[i].name);}if(sum!=0 && i==countn-1)printf("\n");}sum=0;for(i=0;i<counto;i++){if(oldstr[i].flag==2){sum++;if(sum==1)printf("*");printf("%s ",oldstr[i].name);}if(sum!=0 && i==countn-1)printf("\n");}}printf("\n");}return 0;
}
现场赛的C题终于写出来了。。。终于感觉好点了,虽然打码不一定精简,不过也算解了心结了,就因为这题没得奖啊。。。花了1个多小时。。。
这篇关于长嘘一口气。。。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!