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 KatrineYang at 2016-10-24 12:17:17 on Problem 1496
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

char word[8];
int len;
int ljgs[6] = {0,26,351,2951,17901,83681};

int cc(int a, int b){
	int C = 1;
	for(int A = a; A > a-b; A--) C *= A;
	for(int B = b; B > 0; B--) C /= B;
	return C;
}

bool isAsc(){
	len = strlen(word);
	for(int i = 1; i < len; i++){
		if(word[i-1] >= word[i]) return 0;
	}
	return 1;
}

int getOrder(){
	if(!isAsc()) return 0;
	int ans = 1 + ljgs[len-1];
	for(int i = 0; i < len; i++){
		char start;
		if(i == 0) start = 'a';
		else start = word[i-1] + 1;
		for(char c = start; c < word[i]; c++){
			ans += cc(25-(c-'a'), len-i-1);
		}
	}
	return ans;
}

int main() {
	while(scanf("%s", word) > 0){
		printf("%d\n", getOrder());
	}
	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