UVa 12504 Updating a Dictionary

2023-11-18

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;
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UVa 12504 Updating a Dictionary 的相关文章

  • csu 1811 Tree Intersection 2016湖南省赛 I

    Problem acm csu edu cn csuoj problemset problem pid 1811 vjudge net contest 161962 problem I Reference blog csdn net qwb
  • 第八十七题 UVa12166 Equilibrium Mobile

    A mobile is a type of kinetic sculpture constructed to take advantage of the principle of equilibrium It consists of a n
  • 素数打表,复杂度(Onlogn)和O(n)(对与10^7来说线性快两倍) + 分解质因数

    代码 接口 primeInit 100000 打表的范围 素数存在primeList中 个数为primeCount typedef long long LL int const MAXN 10000100 bool isPrime MAXN
  • 【刷题】华为笔试面试机考 [HJ5] - 进制转换

    题目地址 点击跳转 题目描述 写出一个程序 接受一个十六进制的数 输出该数值的十进制表示 输入描述 输入一个十六进制的数值字符串 注意 一个用例会同时有多组输入数据 请参考帖子https www nowcoder com discuss 2
  • 首字母变大写

    小写字母变大写m 0 m 0 32 include
  • hdu 1827 Summer Holiday 强连通分量缩点

    题目 http acm hdu edu cn showproblem php pid 1827 题意 听说lcy帮大家预定了新马泰7日游 Wiskey真是高兴的夜不能寐啊 他想着得快点把这消息告诉大家 虽然他手上有所有人的联系方式 但是一个
  • 蓝桥杯 砝码称重 递归 解题报告

    5个砝码 用天平称重时 我们希望用尽可能少的砝码组合称出尽可能多的重量 如果只有5个砝码 重量分别是1 3 9 27 81 则它们可以组合称出1到121之间任意整数重量 砝码允许放在左右两个盘中 本题目要求编程实现 对用户给定的重量 给出砝
  • stl_set

    begin 返回指向第一个元素的 迭代器 clear 清除所有元素 size 集合中元素的数目 count 返回某个值元素的个数 empty 如果集合为空 返回true 真 end 返回指向最后一个元素之后的迭代器 不是最后一个元素器 in
  • poj 2155 Matrix

    Problem poj org problem id 2155 vjudge net contest 146952 problem A Referencd www cnblogs com gj Acit p 3258880 html Mea
  • UVa 11464 Even Parity 题解

    这是一道白书17页的题目 题目大意 输入一个n n的01矩阵 1
  • hdu 6208 The Dominator of Strings

    Problem acm hdu edu cn showproblem php pid 6208 Meaning 有 n 个字符串 问是否能找到其中一串 使得其它串都是它的子串 Analysis 如果存在这个串 那它一定是 n 个中的最长串
  • gym 101505 CTU Open Contest 2016 G Orchard Division

    Problem codeforces com gym 101505 attachments vjudge net contest 187874 problem G Meaning 一个 m m 的网格 长 宽下标 0 m 1 里有 n 个点
  • ACM学习计划

    看完人家的博客 发现任重道远 一位高手对我的建议 一般要做到50行以内的程序不用调试 100行以内的二分钟内调试成功 acm主要是考算法的 主要时间是花在思考算法上 不是花在写程序与debug上 下面给个计划你练练 第一阶段 练经典常用算法
  • ACM: Poker Game

    题目描述 A poker deck contains 52 cards Each card has a suit of either clubs diamonds hearts or spades denoted C D H S in th
  • hdu 5792 World is Exploding 2016 Multi-University 5

    Problem acm hdu edu cn showproblem php pid 5792 题意 给一个序列 V 问有多少个由下标组成的四元组 a b c d 满足 a b c d a lt b c lt d Va lt Vb Vc g
  • [ACM] 1016 Prime Ring Problem (深度优先搜索)

    Prime Ring Problem Problem Description A ring is compose of n circles as shown in diagram Put natural number 1 2 n into
  • UVa 12504 Updating a Dictionary

    Problem uva onlinejudge org index php option com onlinejudge Itemid 8 page show problem problem 3948 题意 貌似是模拟 Source Cod
  • Ugly Numbers

    题目描述 Ugly numbers are numbers whose only prime factors are 2 3 or 5 The sequence 1 2 3 4 5 6 8 9 10 12 shows the first 1
  • 蓝桥杯 填字母游戏(博弈论)

    小明经常玩 LOL 游戏上瘾 一次他想挑战K大师 不料K大师说 我们先来玩个空格填字母的游戏 要是你不能赢我 就再别玩LOL了 K大师在纸上画了一行n个格子 要小明和他交替往其中填入字母 并且 1 轮到某人填的时候 只能在某个空格中填入L或
  • 杭电ACM 1004题

    原题大概意思就是统计输入字符串中 重复的最大个数 import java util Scanner public class Main public static void main String args Scanner sc new S

随机推荐