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

poj 1002 487-3279

时间:2014-11-18 17:27:06      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   sp   for   div   log   bs   

这是我做的第一道水题来着..

#include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
map<string ,int> m;
string str;
vector <string> q;
char readchar(){
    char ch;
    while(1){
        ch=getchar();
        if(ch>=‘A‘&&ch<‘Q‘){
            ch=(ch-‘A‘)/3+2+‘0‘;
            break;
        }
        else if(ch>‘Q‘&&ch<‘Z‘){
            ch=(ch-‘A‘-1)/3+2+‘0‘;
            break;
        }
        else if(ch<=‘9‘&&ch>=‘0‘){
            break;
        }
    }
    return ch;
}
int main(){
    int k;
	cin>>k;
    while(k--){
        str="";
        for(int i=0;i<7;i++){
            str+=readchar();
        }
        if(m[str]){
            m[str]++;
        }
        else {
            m[str]=1;
            q.push_back(str);
        }
    }
    sort(q.begin(),q.end()-1);
    bool fl=true;
    for(vector<string>::iterator i=q.begin();i<q.end();i++){
        if(m[*i]>1){
            cout<<i->substr(0,3)<<"-"<<i->substr(3,4)<<" "<<m[*i]<<endl;
            fl=false;
        }
    }
    if(fl){
        cout<<"No duplicates."<<endl;
    }
	return 0;
}

  

poj 1002 487-3279

标签:blog   io   ar   os   sp   for   div   log   bs   

原文地址:http://www.cnblogs.com/xuesu/p/4106221.html

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