UVa 12504 Updating a Dictionary (update dictionary)

Source: Internet
Author: User

Test instructions compare two dictionaries output all added delete modified items in dictionary order if there is no update output no changes

Comparison of application of STL map Two dictionaries note the processing of the start string and the dictionary can be empty

#include <bits/stdc++.h>using namespace std;map<string, string> d[2];map<string, String>::iterator    it;const int N = 105;string S, a, B, t[n];void print (char c, int N) {sort (T, T + N), cout << c << t[0];    for (int i = 1; i < n; ++i) cout << ', ' << t[i]; Puts ("");}    int main () {int cas, n, C1, C2, C3;    CIN >> CAs;        while (cas--) {d[0].clear (), d[1].clear ();            for (int i = 0; i < 2; ++i) {cin >> S;            Int j = 1, L = s.size ();                while (L > 2 && J < L) {while (s[j]! = ': ') A + = s[j++]; ++j; while (s[j]! = ', ' && s[j]! = '} ') b + = s[j++];                ++j;                D[i][a] = B, a = b = "";            cout << a << ":" << b << Endl;        }} c1 = C2 = C3 = 0; for (it = D[1].begin (); It! = D[1].end (); ++it) if (!d[0].count (It->first)) t[c1++] = It->fIrst        if (c1) print (' + ', C1);        for (it = D[0].begin (); It! = D[0].end (); ++it) if (!d[1].count (It->first)) t[c2++] = it->first;        if (C2) print ('-', C2); for (it = D[1].begin (); It! = D[1].end (); ++it) if (D[0].count (It->first) && D[0][it->first]! = it-        >second) t[c3++] = it->first;        if (C3) print (' * ', C3); if (! ( C1 | | C2 | |        C3)) puts ("No changes");    Puts (""); } return 0;}

Updating a Dictionary

In this problem, a dictionary is collection of key-value pairs, where keys be lower-case letters, and values are Non-nega tive integers. Given an old dictionary and a new dictionary, find out what were changed.

Each dictionary is formatting as follows:

{ key: value, key: value,..., key: value}

Each key was a string of lower-case letters, and each value is a non-negative integer without leading zeros or prefix ' +'. (i.e. -4, and +77 are illegal). Each key would appear at the most once, but the keys can appear in any order.

InputThe first line contains the number of test cases T (  T -). Each test case contains the lines. The first line contains the old dictionary, and the second line contains the new dictionary. Each line would contain at the most characters and would not be contain any whitespace characters. Both dictionaries could be empty.

WARNING: There is no restrictions on the lengths of all keys and value in the dictionary. That means keys could is really long and values could be really large.

Outputfor each test case, print the changes, formatted as follows:

    • First, if there is any new keys, print '+' and then the new keys in increasing order (lexicographically), Separa Ted by commas.
    • Second, if there is any removed keys, print '-"and then the removed keys in increasing order (lexicographically ), separated by commas.
    • Last, if there is any keys with changed value, print '*' and then these keys in increasing order (Lexicographica lly), separated by commas.

If The dictionaries is identical, print 'No changes' (without quotes) instead.

Print a blank line after each test case.

Sample Input

3{a:3,b:4,c:10,f:6}{a:3,c:5,d:10,ee:4}{x:1,xyz:123456789123456789123456789}{xyz:123456789123456789123456789,x : 1}{first:1,second:2,third:3}{third:3,second:2}

Sample Output

+d,ee-b,f*cno Changes-first

UVa 12504 Updating a Dictionary (update dictionary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.