Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

my answer is correct! but WA!!!

Posted by gholamalih at 2014-09-04 15:33:45 on Problem 1002
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;



typedef struct{
	string str;
	int dup;
}str_dup;
vector<str_dup> dups;
bool dupGrt ( str_dup elem1, str_dup elem2 )
{
	if(elem1.str.compare(elem2.str)<0) return true;
}
void add2dups(string dp){
	int rep=0;
	for(unsigned int i=0; i<dups.size(); i++){
		if(dups[i].str==dp){
			rep++;
			dups[i].dup++;
		}
	}
	if(rep==0){
		str_dup temp;
		temp.str=dp;
		temp.dup=0;
		dups.push_back(temp);
	}
}
int main(){

	int count=0; cin>>count;
	string line;
	vector<string> lines;
	for(int i=0; i<count; i++){
		cin>>line;
		string l2;
		for(unsigned int j=0;j<line.size(); j++){
			if(line[j]!='-'){
				switch(line[j]){
					case 'A': case 'B': case 'C':
						l2.append(1,'2');
						break;
					case 'D': case 'E': case 'F':
						l2.append(1,'3');
						break;
					case 'G': case 'H': case 'I':
						l2.append(1,'4');
						break;
					case 'J': case 'K': case 'L':
						l2.append(1,'5');
						break;
					case 'M': case 'N': case 'O':
						l2.append(1,'6');
						break;
					case 'P': case 'R': case 'S':
						l2.append(1,'7');
						break;
					case 'T': case 'U': case 'V':
						l2.append(1,'8');
						break;
					case 'W': case 'X': case 'Y':
						l2.append(1,'9');
						break;
					default:
						l2.append(1,line[j]);
				}
			}
		}
		l2.insert(3,1,'-');
		//cout<<line<<"    "<<l2<<endl;
		add2dups(l2);
	}
	sort(dups.begin(),dups.end(),dupGrt);
	bool noDup=false;
	for(unsigned int i=0; i<dups.size(); i++){
		if(dups[i].dup>0){
			cout<<dups[i].str<<' '<<dups[i].dup+1<<endl;
			noDup=true;
		}
	}
	if(!noDup){
		cout<<"No duplicates."<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator