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

WA。。。,几个数据都过了,有人帮看看么,代码写的应该很好懂

Posted by kingofcrabs at 2010-12-19 15:45:53 on Problem 1002
#include "stdafx.h"

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<string> NUMBER_STRS_VEC;




char Alphabet2Dig(char ch)
{
	char chDig  = ch;
	
	switch(ch)
	{
		case 'A':
		case 'B':
		case 'C':
			chDig = '2';
			break;
		case 'D':
		case 'E':
		case 'F':
			chDig = '3';
			break;
		case 'G':
		case 'H':
		case 'I':
			chDig = '4';
			break;
		case 'J':
		case 'K':
		case 'L':
			chDig = '5';
			break;
		case 'M':
		case 'N':
		case 'O':
			chDig = '6';
			break;
		case 'P':
		case 'R':
		case 'S':
			chDig = '7';
			break;
		case 'T':
		case 'U':
		case 'V':
			chDig = '8';
			break;
		case 'W':
		case 'X':
		case 'Y':
			chDig = '9';
			break;
		case 'Q':
		case 'Z':
		case '-':
			chDig = ' ';
			break;
	
	}
	return chDig;

}






int main()
{

	
	string s;
	freopen("d:\\input.txt","r",stdin);   
	//get line number
	int totalNum;

	cin>>totalNum;
	
	long const Buf_Size = 10000000;  //10M
	short* pNumbers = new short[Buf_Size];
	memset((void*)pNumbers,0,sizeof(short)*Buf_Size);

	//get the input
	int nCurTelIndex = 0;

	int nMinTelNum = Buf_Size;
	int nMaxTelNum = 0;
	while(cin>>s)
	{
		string sOut = "";
		char chTmp;
		for( int i = 0; i< s.length(); i++)
		{
			chTmp = Alphabet2Dig(s[i]);
			if( chTmp != ' ')
				sOut.push_back(chTmp);

		}
		
		long nVal = atol(sOut.c_str());

		if( nVal > nMaxTelNum)
			nMaxTelNum = nVal;
		if( nVal < nMinTelNum)
			nMinTelNum = nVal;

		pNumbers[nVal]++;
		nCurTelIndex++;
		if(nCurTelIndex == totalNum)
			break;
	}

	NUMBER_STRS_VEC strNumberWithRepeatSuffix;
	
	//format the result
	for( int i = nMinTelNum; i<= nMaxTelNum;i++)
	{
		if( pNumbers[i] > 1)
		{
			char buf[32] = {""};
			sprintf(buf,"%07d %d",i,pNumbers[i]);
			s = buf;
			s.insert(3,"-");
			strNumberWithRepeatSuffix.push_back(s);
		}
	}
	
	
	for( int i = 0;i< strNumberWithRepeatSuffix.size();i++)
	{
		cout<<strNumberWithRepeatSuffix[i]<<endl;
	}


	if( strNumberWithRepeatSuffix.size() == 0 )
	{
		cout<<"No duplicates."<<endl;
	}


	delete []pNumbers;
	
	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