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

大牛们帮小弟看看啊 无限TLEing。。。。

Posted by ljy282 at 2009-10-25 20:19:50 on Problem 1002
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <stdlib.h>
using namespace std;
const char mapp[26] = {'2','2', '2', '3', '3', '3', '4', '4', '4', '5', '5', '5', '6', '6', '6', '7', '@', '7', '7', '8', '8', '8', '9', '9', '9', '@'}; 
typedef struct my_str{
	char ch[100];
	int len;
}my_str,*my_string;

void deal_str(my_str &s,my_str &s1,int *t,int o){        //字符处理
	int j=0;
	for(int i=0;i<s.len&&j<8;++i){
		if((s.ch)[i]>='0'&&(s.ch)[i]<='9'){
			(s1.ch)[j++]=(s.ch)[i];
		}
		
		else if((s.ch)[i]>='A'&&(s.ch)[i]<='Z'){
			if(mapp[(s.ch)[i]-'A']!='@')
				(s1.ch)[j++]=mapp[(s.ch)[i]-'A'];
		}
	}
	s1.ch[8]='\0';
	t[o]=atoi(s1.ch);
}

int main(){
	int n,num=1,j,x,sign=0;
	my_string s,s1;
	scanf("%d",&n);
	s=new my_str[n];
	s1=new my_str[n];
	int *t=new int[n];
	for(int i=0;i<n;++i){      //初始化
		scanf("%s",s[i].ch);
		s[i].len=(int)(strlen(s[i].ch));
	}
	for(int i=0;i<n;++i)
		deal_str(s[i],s1[i],t,i);

	sort(t,t+n);//排序

	for(int i=0;i<n-1;){
		num=1;
		for(j=i+1;j<n;++j){
			if(t[i]==t[j]){
				++num;
				x=j;
			}
		}
		if(num>1){
			sign=1;
			printf("%03d-%04d %d\n",t[i]/10000,t[i]%10000,num);
			i=x;
		}
		else ++i;
	}

	if(sign==0) printf("No duplicates.\n");
	delete []s;delete []s1;delete []t;
	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