zoukankan      html  css  js  c++  java
  • POJ 2643

    map 水题

     1 #include <map>
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <cstring>
     6 #include <string>
     7 using namespace std;
     8 map<string,int > a;
     9 map<string,string> b;
    10 
    11 int main(){
    12     //freopen("test.txt","r",stdin);
    13     int n,m;
    14     char s1[85],s2[85];
    15     scanf("%d",&n);
    16     getchar();
    17     for(int i=0;i<n;i++){
    18         cin.getline(s1,85,'
    ');
    19         cin.getline(s2,85,'
    ');
    20         a[s1]=1;
    21         b[s1]=s2;
    22     }
    23     scanf("%d",&m);
    24     getchar();
    25     int max1=0,count1=0;
    26     string st;
    27     for(int i=0;i<m;i++){
    28         cin.getline(s1,85,'
    ');
    29         if(a[s1]==0)continue;
    30         a[s1]++;
    31         if(a[s1]==max1)count1++;
    32         if(a[s1]>max1){
    33             max1=a[s1];
    34             st=b[s1];
    35             count1=1;
    36         }
    37     }
    38     if(count1==1){
    39         cout<<st<<endl;
    40     }
    41     else cout<<"tie"<<endl;
    42 
    43 }

    #include <map>
    #include <cstdio>
    #include <iostream>
    #include <string.h>
    #include <cstring>
    #include <string>
    using namespace std;
    map<string,int > a;
    map<string,string> b;

    int main(){
        freopen("test.txt","r",stdin);
        int n,m;
        char s1[85],s2[85];
        scanf("%d ",&n);
        //getchar();
        for(int i=0;i<n;i++){
            cin.getline(s1,85,' ');
            cin.getline(s2,85,' ');
            a[s1]=1;
            b[s1]=s2;
        }
        scanf("%d ",&m);
        //getchar();
        int max1=0,count1=0;
        string st;
        for(int i=0;i<m;i++){
            cin.getline(s1,85,' ');
            if(a[s1]==0)continue;
            a[s1]++;
            if(a[s1]==max1)count1++;
            if(a[s1]>max1){
                max1=a[s1];
                st=b[s1];
                count1=1;
            }
        }
        if(count1==1){
            cout<<st<<endl;
        }
        else cout<<"tie"<<endl;

    }

  • 相关阅读:
    spring对事务的配置
    Mysq中的流程控制语句的用法
    mysql存储过程和常用流程控制
    ztree更换节点图标
    eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过
    myeclipse如何设置或关闭断点调试自动跳入debug模式
    Druid数据源对数据库访问密码加密好麻烦
    js中if()条件中变量为false的情况
    TFS2008 安装图解(详细版本)(转载)
    数字格式化
  • 原文地址:https://www.cnblogs.com/Mr-Xu-JH/p/3884475.html
Copyright © 2011-2022 走看看