Unity Common script: PHYSICS

2023-01-22   ES  

Question meaning compares the two dictionaries to output all the items that are added and deleted by the dictionary. If there is no update output No Changes

STL MAP Application Comparison Two Dictionary Pay attention to the processing and dictionary of the starting string can be empty

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

int main()
    int cas, n, c1, c2, c3;
    cin >> 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");
    return 0;

  Updating a Dictionary 

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

Each dictionary is formatting as follows:


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


The first line contains the number of test cases 
T$ \le$1000
). Each test case contains two lines. The first line contains the old dictionary, and the second line contains the new dictionary. Each line will contain at most 100 characters and will not contain any whitespace characters. Both dictionaries could be empty.

WARNING: there are no restrictions on the lengths of each key and value in the dictionary. That means keys could be really long and values could be really large.


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

  • First, if there are any new keys, print `+‘ and then the new keys in increasing order (lexicographically), separated by commas.
  • Second, if there are any removed keys, print `-‘ and then the removed keys in increasing order (lexicographically), separated by commas.
  • Last, if there are any keys with changed value, print `*‘ and then these keys in increasing order (lexicographically), separated by commas.

If the two dictionaries are identical, print `No changes‘ (without quotes) instead.

Print a blank line after each test case.

Sample Input 


Sample Output 


No changes



Related Posts

Maven’s basic use

15. Shang Rongbao’s background to implement data dictionary, import, export

Set up DVWA penetration test target

[docker] Two docker-compose.xml sharing a network

Unity Common script: PHYSICS

Random Posts

pycharm cracking method

1 1 1 Five data structures under the bottom layer implementation (moving picture version)

Matplotlib The difference between Matshow and imshow in Matplotlib

Spring integrated Redis tutorial

Core Technology (Volume 2) 02, Chapter 1-Regular expression