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 |
一直是WA,请高手看一下什么原因,谢谢#include <iostream> #include <string> #include <vector> #include <map> #include <stdlib.h> #include <algorithm> #include <math.h> using namespace std; inline int change(char a) { switch (a){ 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; default:break; } } int convert(string number) { int rNumber = 0; //covert the letter to number string::iterator i = number.begin(); for(int j = 6 ; i != number.end(); i++, j--) { //trim the '-' in number if(*i == '-' || *i == 'Q' || *i == 'Z'){ number.erase(i); i--,j++;continue; }else if(*i>='A' && *i <= 'Z'){ //change letter to number rNumber += change(*i) * pow(10.0,j); continue; }else{ rNumber += (*i - '0' ) * pow(10.0,j); } //ignore original number } return rNumber; } int Compare(const void *one,const void *two) { int a = *((int*)one); int b = *((int*)two); if (a<b) return -1; if (a == b) return 0; return 1; } int main(){ //get the number of the list vector<string>::size_type nLen = 0; cin >> nLen; //map<string,int> resultList; //input to numberList vector<int> numberList; for(int i = 0; i < nLen; i++) { string number; cin >> number; int result = convert(number); numberList.push_back(result); /* map<string,int>::iterator iter = resultList.find(result); if(iter == resultList.end()) { pair<string,int> value(result,1); resultList.insert(value); }else{ iter->second += 1; }*/ } /*for(map<string,int>::iterator i = resultList.begin(); i != resultList.end(); i++) { if(i->second == 1) { //cout << i->first <<" No duplicates." << endl; continue; }else{ cout << i->first <<" "<< i->second << endl; } //cout << i->first <<" "<< i->second << endl; } */ qsort(&numberList[0],nLen,sizeof(int),Compare); bool flag = false; for(vector<int>::iterator i = numberList.begin(),j = i; i != numberList.end(); i = j ) { int count = 0; while(*i == *j){ count++; j++; }; if(count > 1) { cout << *i/10000<<"-"<<*i%10000<<" "<<count << endl; flag = true; } //if(j == numberList.end()) break; } if(!flag)cout<< "No duplicates.\n"; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator