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

为什么老通不过啊!!求助!!!

Posted by woshiliyiyiyiyi at 2011-09-22 01:44:00
#include<stdio.h>
#include<string.h>
#include<string.h>

int change(char a[][50], int n)
{
	int i;
	int k;
	int g;
	int j;
	for(i=0 ;i<n; i++) {
		k = strlen(a[i]);
		g = 0;
		for(j=0 ;j<k; j++) {
			
			if(a[i][j] >= 'A' && a[i][j] <= 'P')
				a[i][j] = (a[i][j] - 'A')/3 + '2';
			else if(a[i][j] >= 'R' && a[i][j] <= 'Z')
				a[i][j] = (a[i][j] - 'Q')/3 + '7';
			
			if(a[i][j] != '-') 
				a[i][g++] = a[i][j];
			
			if(g == 3)
				a[i][g++] = '-';
		}
		a[i][8] = '\0';
	}
	return 0;
}

int exchange(char a[][50], int lift, int right)
{
	int low = lift, high = right;
	char flag[50];
	
	strcpy(flag, a[lift]);

	while(low < high) {
		while(low < high && strcmp(a[high],flag) >= 0)
			high--;
		if(low < high) {
			strcpy(a[low], a[high]);
			low++;
		}
		
		while(low < high && strcmp(a[low], flag) <= 0) {
			low++;
		}
		if(low < high) {
			strcpy(a[high], a[low]);
			high--;
		}
	}

	strcpy(a[low], flag);

	if(right > lift + 1) {
		exchange(a, lift, low);
		exchange(a, low+1, right); 
	}
	
	return low; 
}


int fun(char a[][50],int n)
{
	int i;
	int j;
	int found = 0;
	j = 1;
	for(i=1 ;i<n; i++) {
		if(strcmp(a[i],a[i-1]) == 0)
			j++;
		else {
			if(j > 1)
			{
				printf("%s %d\n", a[i-1],j);
				found = 1;
			}
			j = 1;
		}
	}
	if(j > 1) {
		found = 1;
		printf("%s %d\n", a[i-1],j);
	}

	if(found == 0)
		printf("No duplicates.\n");
	return 0;
}

int main()
{
	char a[100000][50];
	int n;
	int i;
	
	scanf("%d", &n);
	for(i=0 ;i<n; i++) {
		a[i][0] = '-';
		fscanf(stdin,"%s",a[i]+1);
	}

	change(a,n);
	exchange(a, 0, n-1);
	fun(a,n);
	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