poj1002

前几个号码是0的时候一开始忘了处理

把位数控制好就行了

QZ我是没管他们

然后就竟然过了

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<map>
using namespace std;
int hsh[10000000];
int trs(char a){
    if(a>='A'&&a<='C'){
        return 2;
    }
    if(a>='D'&&a<='F'){
        return 3;
    }
    if(a>='G'&&a<='I'){
        return 4;
    }
    if(a>='J'&&a<='L'){
        return 5;
    }
    if(a>='M'&&a<='O'){
        return 6;
    }
    if(a>='P'&&a<='S'){
        return 7;
    }
    if(a>='T'&&a<='V'){
        return 8;
    }
    if(a>='W'&&a<='Y'){
        return 9;
    }
    return 0;
}
int main(){
    int T;
    char str[20];
    cin>>T;
    memset(hsh,0,sizeof(hsh));
    while(T--){
        cin>>str;
        int tmp,flg;
        tmp=0;
        flg=1000000;
        int len=strlen(str);
        for(int i=0;i<len;i++){
            if(str[i]=='-'){
                continue;
            }
            else{
                if(str[i]<='9'&&str[i]>='0'){
                    tmp+=(str[i]-'0')*flg;
                    flg/=10;
                }
                else{
                    tmp+=trs(str[i])*flg;
                    flg/=10;
                }
            }
        }
        hsh[tmp]++;
    }
    int flag=1;
    for(int i=0;i<=9999999;i++){
        if(hsh[i]==0){
            continue;
        }
        if(hsh[i]>=2){
            flag=0;
            for(int t=100;t>=1;t/=10){
                if(i/10000<t){
                    cout<<"0";
                }
            }
            if(i/10000!=0){
                cout<<i/10000;
            }
            cout<<"-";
            for(int t=1000;t>=1;t/=10){
                if(i%10000<t){
                    cout<<"0";
                }
            }
            if(i%10000!=0){
                cout<<i%10000;
            }
            cout<<" "<<hsh[i]<<endl;
        }
    }
    if(flag){
        cout<<"No duplicates."<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值