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

帮我看一下错在哪里。。。谢谢。是RE.

Posted by direfire at 2007-10-30 19:50:53 on Problem 1240
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>

using namespace std;
int m;
char pre[30], post[30];
int len;

long long comp(long long a1, long long b1)
{
	if (a1 == 1) return 1;
	if (b1 ==1) return a1;
	if (a1-b1 < b1) b1 = a1-b1;
	long long ret = 1;
	for (long long i = a1; i >= (a1-b1+1); i--) ret *= i;
	for (long long i = b1; i >= 1; i--) ret/=i;
	return ret;
}
long long parse(char *start, char *end, int l)
{
	if (l == 0) return 1;
	if (l == 1) return 1;
	long long ret = 1;
	int index[27];
	for (int i = 1; i < l; i++)
	   for (int j = 0; j < l-1; j++)
	     if (start[i] == end[j]) { index[i] = j; break;}
	int id = 1;
	int count = 0;
	while(id < l)
	{
		int p = index[id];
		int f = 0;
		char pe[27], po[27];
		memset(pe, '\0', sizeof(pe));
		memset(po, '\0', sizeof(po));
		while(p >= index[id] && id < len) {pe[f] = start[id]; po[f] = end[id-1]; f++; id++;}
	  ret *= parse(pe, po, f);
		count++;
	} 
	ret *= comp(m, count);
  return ret;
}

int main()
{
  while(1)
  {
    scanf("%d", &m);
    if (m == 0) break;
    memset(pre, '\0', sizeof(pre));	
    memset(post, '\0', sizeof(post));	
    scanf("%s %s", &pre, &post);
    len = strlen(pre);
    long long res = parse(pre, post, len);
    printf("%ld\n", res);
  }	
	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