poj1002(map水题 )

给你一些字符,统一转化成电话号码,放在map 输出他们个数。
string 时间TLE char 过了

#include <fstream>
#include <iostream>
#include <string>
#include<cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=1000000007;
const int inf=99999999;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

using namespace std;
int cal(char c)
{
    switch(c){
    case 'A':
    case 'B':
    case 'C': return 2;
    case 'D':
    case 'E':
    case 'F': return 3;
    case 'G':
    case 'H':
    case 'I': return 4;
    case 'J':
    case 'K':
    case 'L': return 5;
    case 'M':
    case 'N':
    case 'O': return 6;
    case 'P':
    case 'R':
    case 'S': return 7;
    case 'T':
    case 'U':
    case 'V': return 8;
    case 'W':
    case 'X':
    case 'Y': return 9;
    }
}

int main()
{
    map<int,int>dict;
   // set<int>;
    dict.clear();
    int T;scanf("%d",&T);
    while(T--){
        char s[50];scanf("%s",s);
        int num=0;
        for(int i=0;i<strlen(s);i++){
        if(s[i]=='-') continue;
        else if(s[i]>='A'&&s[i]<='Z') num=num*10+cal(s[i]);
        else num=num*10+s[i]-'0';
        }
        dict[num]++;
    }
    bool flag=false;
    for(map<int,int>::iterator it=dict.begin();it!=dict.end();it++)
    {
        if(it->second>1) {
        printf("%03d-%04d %d\n", it->first / 10000, it->first % 10000, it->second);
        flag=true;
        }
    }
    if(!flag) cout<<"No duplicates."<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值