zoukankan      html  css  js  c++  java
  • UVA12504【C++STL运用】

    雨巨的UVA的C++题集英文真长…
    题意:
    有两本字典,第一行是旧字典,第二行是新字典。
    每行不超过100个字符,没有空格,两本字典都可以是空的;
    新key:+
    缺key:-
    值变 :*
    思路:
    具体见代码,具体参考http://blog.csdn.net/acvay/article/details/43021077
    这里会出现一个count函数
    algorithm头文件定义了一个count的函数,其功能类似于find。这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果。
    编写程序读取一系列int型数据,并将它们存储到vector对象中,然后统计某个指定的值出现了多少次

    //#include <bits/stdc++.h>
    #include<cstdio>
    #include<iostream>
    #include<queue>
    #include<map>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    
    map<string,string>d[2];
    map<string,string>::iterator it;
    
    void init()
    {
        d[0].clear();
        d[1].clear();
    }
    string t[110];
    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 T;
        scanf("%d",&T);
        while(T--)
        {
            init();
            string s,a,b;
            for(int i=0;i<2;++i)
            {
                cin>>s;
                int j=1,len=s.size();
                while(len>2&&j<len)
                {
                    a=b="";
                    while(s[j]!=':')
                        a+=s[j++];
                    j++;
                    while(s[j]!=','&&s[j]!='}')
                        b+=s[j++];
                    j++;
                    d[i][a]=b;
                    //cout<<a<<":"<<b<<endl;
                }
            }
            int c1,c2,c3;
            c1=c2=c3=0;
            //访问新字典,如果旧字典key不存在,那么就一定多了;
            for(it=d[1].begin();it!=d[1].end();it++)
                if(!d[0].count(it->first))
                    t[c1++]=it->first;
            if(c1)
            print('+',c1);
    
            //访问旧字典,如果新字典key不存在,那么就一定少了;
            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;
    }
    
  • 相关阅读:
    项目Alpha冲刺(团队)-代码规范、冲刺任务与计划
    团队Github实战训练
    项目系统设计与数据库设计
    项目需求分析
    项目原型设计
    项目Alpha冲刺(团队)-第六天冲刺
    项目Alpha冲刺(团队)-第五天冲刺
    项目Alpha冲刺(团队)-第四天冲刺
    项目Alpha冲刺(团队)-第三天冲刺
    项目Alpha冲刺(团队)-第二天冲刺
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934784.html
Copyright © 2011-2022 走看看