Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
跪求大神指点#include<vector> #include<string> #include<map> #include<cctype> #include<iterator> #include<iostream> using std::cin; using std::cout; using std::endl; #ifndef _Parse_H #define _Parse_H class Parse{ public: Parse() { numMapLetter["ABC"] = '2'; numMapLetter["DEF"] = '3'; numMapLetter["GHI"] = '4'; numMapLetter["JKL"] = '5'; numMapLetter["MNO"] = '6'; numMapLetter["PRS"] = '7'; numMapLetter["TUV"] = '8'; numMapLetter["WXY"] = '9'; } Parse(const std::vector<std::string> vecStr):vecString(vecStr) { numMapLetter["ABC"] = '2'; numMapLetter["DEF"] = '3'; numMapLetter["GHI"] = '4'; numMapLetter["JKL"] = '5'; numMapLetter["MNO"] = '6'; numMapLetter["PRS"] = '7'; numMapLetter["TUV"] = '8'; numMapLetter["WXY"] = '9'; } void setVecStr(std::string str); void setMap(); std::map<std::string,std::size_t> getResultMap()const; private: std::vector<std::string> vecString; std::map<std::string,std::size_t> resultMap; std::map<std::string , char> numMapLetter; }; #endif void Parse::setVecStr(std::string str) { if(str.size()<7||str.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-")!=std::string::npos) return; vecString.push_back(str); setMap(); } void Parse::setMap() { std::string str = vecString[vecString.size()-1]; if(str[3] != '-') { str.insert(3,1,'-'); } //std::cout<<str<<std::endl; std::size_t i = 0; while(i < str.size()) { //删除多余的'-' if(str[i] == '-') { if(i == 3) { i++; } else { str.erase(i,1); } continue; } if(str[i]=='Q'||str[i]=='Z') { i++; continue; } //字符转换为数字 if(!isdigit(str[i])) { std::map<std::string,char>::iterator mIter; for(mIter = numMapLetter.begin();mIter != numMapLetter.end();mIter++) { if(mIter->first.find(str[i]) != std::string::npos) { str[i]=mIter->second; break; } } } i++; } //std::cout<<i<<std::endl<<str<<std::endl; if(str.size()==8) { resultMap[str]++; } } std::map<std::string,std::size_t> Parse::getResultMap()const { return resultMap; } int main() { bool flag=false; Parse parse; std::map<std::string,std::size_t> resultMap; std::string str; int i,num; cin>>num; if(num<=0||num>100000) return 0; i=0; while(i<num) { cin>>str; parse.setVecStr(str); i++; } resultMap=parse.getResultMap(); std::map<std::string,std::size_t>::iterator mIter; for(mIter = resultMap.begin();mIter != resultMap.end();mIter++) { if(mIter->second>1) { flag=true; cout<<mIter->first<<" "<<mIter->second<<endl; } } if(!flag) { cout<<"No duplicates."<<endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator