poj1002不会超时

#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#define SIZE 200000
using namespace std;

int formal(string s){
    int ans = 0;
    char ch ;
    for(int i=0;i<s.length();i++){
        if(s.at(i) != '-'){
            if(s.at(i) == '0' || s.at(i) == '1'){
                ch = s.at(i);
            }    
            if(s.at(i) == 'A' || s.at(i) == 'B' || s.at(i) == 'C' || s.at(i) == '2'  ){
                ch = '2';
            }
            if(s.at(i) == 'D' || s.at(i) == 'E' || s.at(i) == 'F' || s.at(i) == '3'  ){
                ch = '3';
            }  
            if(s.at(i) == 'G' || s.at(i) == 'H' || s.at(i) == 'I' || s.at(i) == '4'  ){
                ch = '4';
            }  
            if(s.at(i) == 'J' || s.at(i) == 'K' || s.at(i) == 'L' || s.at(i) == '5'  ){
                ch =  '5';
            }  
            if(s.at(i) == 'M' || s.at(i) == 'N' || s.at(i) == 'O' || s.at(i) == '6'  ){
                ch = '6';
            }  
            if(s.at(i) == 'P' || s.at(i) == 'R' || s.at(i) == 'S' || s.at(i) == '7'  ){
                ch = '7';
            }  
            if(s.at(i) == 'T' || s.at(i) == 'U' || s.at(i) == 'V' || s.at(i) == '8' ){
                ch = '8';
            }  
            if(s.at(i) == 'W' || s.at(i) == 'X' || s.at(i) == 'Y' || s.at(i) == '9'  ){
                ch = '9';
            }  
            ans = ans * 10  + ch - '0'; 
       }    
         else{}
         
    }  
    return ans;  
}   


int compare(const void * a,const void * b){
   return *(int*)a-*(int*)b;
}    

int main(void){
    
    int test;
    cin>>test;
    int v[SIZE];
    for(int t=0;t<test;t++){
        string x;
        cin>>x;
        int y = formal(x);
        v[t] = y;
    } 
    
    
    qsort(v,test,sizeof(int),compare);
    int pos = 0;
    int flag = 0;
    while(pos<test) {
        //cout<<v[pos]<<endl;
        int last = pos ;
        while(v[pos+1]==v[pos]){
            pos ++;
           // cout<<v[pos]<<endl;
        } 
        if(last != pos){
            printf("%03d-%04d %d\n",v[pos]/10000,v[pos]%10000,pos-last+1);
            flag = 1;
        }  
        pos++;     
    }
    if(flag == 0){
         cout<<"No duplicates."<<endl;
     }        
    //system("pause");  
    return 0;
}     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值