POJ 1002 用map容器写的,自己运行对了,提交确实 wrong answer,怎么回事

来源:互联网 发布:mac safari广告净化器 编辑:程序博客网 时间:2024/04/29 06:54
#include <iostream>using namespace std;#include <string>#include <map>char AlphaToInteger(char ch);void printTelNum(string str);int main(){int n=0,i=0,j=0,len=0,ncount=1;cin>>n;string *str=new string[n];string::iterator str_it;map<string,int> strMapName;map<string,int>::iterator it;for (i=0;i<n;i++){cin>>str[i];for (str_it=str[i].begin();str_it != str[i].end();++str_it){if (*str_it=='-'){str[i].erase(str_it);// 删除最后一个字符——出错}if (str_it==str[i].end()){break;}}len=str[i].length();for (j=0;j<len;j++){if (str[i][j]>'9'){str[i][j]=AlphaToInteger((char)str[i][j]);}}if (strMapName.count(str[i])){it=strMapName.find(str[i]);it->second+=1;}else{strMapName.insert(map<string,int>::value_type(str[i],1));}}string temp;int flag=0;for (it=strMapName.begin();it != strMapName.end();it++){if (it->second>1){flag=1;temp=it->first;printTelNum(temp);cout<<" "<<it->second<<endl;}}if (flag==0){cout<<"No duplicates."<<endl;}return 0;}char AlphaToInteger(char ch){char temp;switch (ch){case 'A':case 'B':case 'C':temp='2';break;case 'D':case 'E':case 'F':temp='3';break;case 'G':case 'H':case 'I':temp='4';break;case 'J':case 'K':case 'L':temp='5';break;case 'M':case 'N':case 'O':temp='6';break;case 'P':case 'R':case 'S':temp='7';break;case 'T':case 'U':case 'V':temp='8';break;case 'W':case 'X':case 'Y':temp='9';break;}return temp;}void printTelNum(string str){int i=0,len=0;len=str.length();for (i=0;i<len;i++){cout<<str[i];if (i==2){cout<<'-';}}}

0 0
原创粉丝点击