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 oeym at 2006-03-24 11:03:12 on Problem 1496
#include <stdio.h>
#include <string.h>
int C[28][12];
char s[12];

int pre()
{
	int i, j;
	for (i = 0; i < 28; i++)
	{
		C[i][0] = 1;
	}
	for (i = 0; i < 12; i++)
	{
		C[i][i] = 1;
	}
	for (i = 1; i < 28; i++)
	{
		for (j = 1; j < 12 && j <= i; j++)
		{
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
}

int check()
{
	int i, l, ans, j;
	l = strlen(s);
	for (i = 0; i < l - 1; i++)
	{
		if (s[i] >= s[i + 1])
		{
			return 0;
		}
	}
	ans = 0;
	for (i = 0; i < l; i++)
	{
		ans += C[26][i];
	}
	for (i = 0; i < s[0] - 'a'; i++)
	{
		ans += C[25 - i][l - 1];
	}
	for (i = 1; i < l; i++)
	{
		for (j = s[i - 1] - 'a'; j < s[i] - 'a' - 1; j++)
		{
			ans += C[25 - j][l - i - 1];
		}
	}
	return ans;
}

int main()
{
	int i;
	pre();
	while (scanf("%s", s) != -1)
	{
		printf("%d\n", check());
	}
	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