码迷,mamicode.com
首页 > 其他好文 > 详细

2016百度之星资格赛

时间:2016-05-14 23:00:13      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

A.前缀hash+逆元

技术分享
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

const int inf = 0x3f3f3f;
const int MAXN = 1e7+10;

using namespace std;


int main()
{
    int n;
    char ts[40];
    map<string,int>hash;
    map<string,int>::iterator li;
    while(scanf("%d",&n)!=EOF){
        hash.clear();
        for(int i=0;i<n;i++){
            scanf("%s",ts);
            int len = strlen(ts);
            sort(ts,ts+len);
            string tmp = (string)ts;
                li = hash.find(tmp);
                if(li==hash.end()){
                    cout<<0<<endl;
                    hash[tmp]++;
                }else{
                    cout<<hash[tmp]<<endl;
                    hash[tmp]++;
                }
            }

    }
    //cout << "Hello world!" << endl;
    return 0;
}
View Code

 

D.sort+map

技术分享
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

const int inf = 0x3f3f3f;
const int MAXN = 1e7+10;

using namespace std;


int main()
{
    int n;
    char ts[40];
    map<string,int>hash;
    map<string,int>::iterator li;
    while(scanf("%d",&n)!=EOF){
        hash.clear();
        for(int i=0;i<n;i++){
            scanf("%s",ts);
            int len = strlen(ts);
            sort(ts,ts+len);
            string tmp = (string)ts;
                li = hash.find(tmp);
                if(li==hash.end()){
                    cout<<0<<endl;
                    hash[tmp]++;
                }else{
                    cout<<hash[tmp]<<endl;
                    hash[tmp]++;
                }
            }

    }
    //cout << "Hello world!" << endl;
    return 0;
}
View Code

 

2016百度之星资格赛

标签:

原文地址:http://www.cnblogs.com/EdsonLin/p/5493448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!