Problem
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3948
题意
貌似是模拟?
Source Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char chg;
char key[100],val[100];
}node;
node que[100];
int top,plus,neg,star;
int cmp(const void *a,const void *b)
{
node *c=(node*)a,*d=(node*)b;
return strcmp(c->key,d->key);
}
void read_old()
{
char in=getchar();
in=getchar();
while(in!='}')
{
int i;
for(i=0;in!=':'&&in!='}';i++)
que[top].key[i]=in=getchar();
if(in=='}') return;
que[top].key[i-1]='\0';
for(que[top].val[i=0]='\0';in!=','&&in!='}';i++)
que[top].val[i]=in=getchar();
que[top].val[i-1]='\0';
que[top++].chg='-';
}
neg=top;
}
void read_new()
{
char tkey[100],tval[100],in=getchar();
in=getchar();
while(in!='}')
{
int j;
for(j=0;in!=':'&&in!='}';j++)
tkey[j]=in=getchar();
if(in=='}') return;
tkey[j-1]='\0';
for(tval[j=0]='\0';in!=','&&in!='}';j++)
tval[j]=in=getchar();
tval[j-1]='\0';
for(j=0;j<top;j++)
if(!strcmp(tkey,que[j].key))
break;
if(j<top)
if(!strcmp(tval,que[j].val))
{
que[j].chg='n';
neg--;
}
else
{
que[j].chg='*';
neg--;
star++;
}
else
{
strcpy(que[top].key,tkey);
que[top++].chg='+';
plus++;
}
}
}
void print(int num,char ch)
{
int i;
putchar(ch);
for(i=0;i<top;i++)
if(que[i].chg==ch)
{
printf("%s%c",que[i].key,",\n"[num==1]);
if(--num==0) return;
}
}
int main()
{
int iTom;
scanf("%d",&iTom);
while(iTom--)
{
int i;
top=plus=neg=star=0;
read_old();
read_new();
qsort(que,top,sizeof(node),cmp);
if(!plus&&!neg&&!star)
{
puts("No changes\n");
continue;
}
if(plus) print(plus,'+');
if(neg) print(neg,'-');
if(star) print(star,'*');
putchar('\n');
}
return 0;
}