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 applemilk at 2015-03-11 22:27:41 on Problem 1496
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int jinwei(char ch1[], int max)
{
	int i;
	i = max - 1;
	while(ch1[i] == (27 - max + 1 + i))
	{
		ch1[i - 1]++;
		i--;
	}
	return i;
}

void jiayi(char ch1[], int max, int k)
{
	while(k < max)
	{
		ch1[k] = ch1[k - 1] + 1;
		k++;
	}
	return;
}

char ch[105], ch1[105];

int main(int argc, char *argv[])
{
	int i, j, k, max, ans, cheng = 26, sum[27] = {0};
	memset(ch, 0, sizeof(ch));
	memset(ch1, 0, sizeof(ch1));
	sum[1] = 0;
	sum[2] = 26;
	for(i = 3;i <= 26;i++)
	{
		cheng = 26;
		for(j = 1;j < (i - 1);j++)
        {
              cheng *= (26 - j);
              cheng /= j;   	
        }
        cheng = cheng / (i - 1);
        sum[i] = sum[i - 1] + cheng;
	}
	while(scanf("%s", ch) != EOF)
	{
		k = 0;
		max = strlen(ch);
		ans = sum[max];
		for(i = 0;i < max;i++)
		{
			ch[i] = ch[i] - 'a' + 1;
			if(ch[i] <= ch[i - 1]&&i != 0)
			{
				k = 1;
				printf("0\n");
				break;
			}
		}
		if(k == 1)
		continue;
		k = max - 1;
	    while(k >= 0)
		{
			ch1[k] = k + 1;
			k--;
		}	
		while(memcmp(ch, ch1, max) != 0)
		{
			ch1[max - 1]++;
			ans++;
			while(ch1[max - 1] == 27)
			{
                k = jinwei(ch1, max);
                jiayi(ch1, max, k + 1);
			}
		}
		printf("%d\n", ans + 1);
		memset(ch, 0, sizeof(ch));
		memset(ch1, 0, sizeof(ch1));
	}
	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