首页 > 其他 > 详细

poj 1002 487-3279

时间:2014-11-18 17:25:04      阅读:207      评论:0      收藏:0      [点我收藏+]

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

#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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!