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

C++可过, G++不可过的代码

Posted by kvsl at 2017-06-27 14:03:20 on Problem 1002
#include <iostream>
#include <string>
#include <map>

#define MAXLEN 100
#define FIXEDLEN 9

using namespace std;
int main()
{
	char seq[100];
	seq['A']=seq['B']=seq['C']='2';
	seq['D']=seq['E']=seq['F']='3';
	seq['G']=seq['H']=seq['I']='4';
	seq['J']=seq['K']=seq['L']='5';
	seq['M']=seq['N']=seq['O']='6';
	seq['P']=seq['R']=seq['S']='7';
	seq['T']=seq['U']=seq['V']='8';
	seq['W']=seq['X']=seq['Y']='9';

	map<string, int> dist;
	int n;	//输入的数据行数
	char ch[MAXLEN];   //暂存输入的数据
	char tmp[FIXEDLEN];  //存入输出的数据

	while(cin>>n){
		for(int i=0; i<n; i++){
			cin>>ch;
			int k=0;
			for(int j=0; ch[j]!='\0'; j++){
				if(ch[j]=='-')
					continue;
				if(k==3)
					tmp[k++] = '-';
				if(ch[j]>='0' && ch[j]<='9')
					tmp[k++]=ch[j];
				else
					tmp[k++]=seq[ch[j]];
			}
			tmp[k]='\0';
			dist[tmp]++;
		}
		bool flag = true;
		for(map<string, int>::iterator itr=dist.begin(); itr!=dist.end(); itr++){
			if(itr->second > 1){
				cout<<itr->first<<' '<<itr->second<<endl;
				flag=false;
			}
		}
		if(flag)
			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