• 更新字典 (Updating a Dictionary,UVa12504)


    题目描述:

    解题思路:

    1.根据:和,获得字符串

    2.使用两个map进行比较;

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <string>
     4 #include <map>
     5 using namespace std;
     6 map<string, string>::iterator it;
     7 map<string,string> dict[2];
     8 string str[105];
     9 int main(int argc, char *argv[])
    10 {
    11     int t ;
    12     cin >> t;
    13     while(t--)
    14     {
    15         dict[0].clear(), dict[1].clear();
    16         for(int i=0;i<2;i++)
    17         {
    18             string s,t1,t2;
    19             cin >> s ;
    20             int j=1,len = s.size() ;
    21             while(j < len && len > 2)
    22             {
    23                 while(s[j]!=':') t1 += s[j++] ; ++j ;
    24                 while(s[j]!=',' && s[j]!='}') t2 += s[j++] ; ++j ;
    25                 dict[i][t1] = t2 ;
    26                 t1 = t2 = "" ; 
    27             } 
    28         }    
    29         int a=0,s=0,m=0;
    30         for(it=dict[1].begin();it != dict[1].end();it++)
    31             if(!dict[0].count(it->first)) str[a++] = it->first;
    32         if(a)
    33         {
    34             sort(str,str+a);
    35             cout << "+" << str[0]  ;
    36             for(int i = 1; i < a; ++i) cout << ',' << str[i];    
    37             puts("");
    38         }
    39         for(it=dict[0].begin();it != dict[0].end();it++)
    40             if(!dict[1].count(it->first)) str[s++] = it->first;
    41         if(s)
    42         {
    43             sort(str,str+s);
    44             cout << "-" << str[0]  ;
    45             for(int i = 1; i < s; ++i) cout << ',' << str[i];
    46             puts("");    
    47         }
    48         for(it=dict[1].begin();it != dict[1].end();it++)
    49             if(dict[0].count(it->first)&&dict[0][it->first] != it->second) str[m++] = it->first;
    50         if(m)
    51         {
    52             sort(str,str+m);
    53             cout << "*" << str[0]  ;
    54             for(int i = 1; i < m; ++i) cout << ',' << str[i];    
    55             puts("");
    56         }
    57         if(!(a || s || m)) puts("No changes");
    58         puts("");
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    Java中的数据类型
    SSE2 Intrinsics各函数介绍[转]
    mac terminal的使用技巧
    vi打开二进制文件
    svn
    fitness
    <正见>摘抄
    管理自己
    [C++程序设计]基于对象的程序设计 基于对象的程序设计
    [C++程序设计]引用
  • 原文地址:https://www.cnblogs.com/secoding/p/9495592.html
Copyright © 2020-2023  润新知