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

为什么WA了???

Posted by sdau_09_wukon at 2010-10-16 16:55:14 on Problem 2739
#include <iostream>
using namespace std;

int t[100] = {0};
bool isPrime(int num) {
	int i = 2;
	for(;i <= num / 2;i++) {
		if(num%i == 0)
			return false;
	}
	return true;
}

void move(int *t,int &length,int &sum) {
	sum = sum - t[0];
	int j=1;
	for(;j < length;j++){
		t[j-1] = t[j]; 
	}
	length--;
}

int main(void) {
	int i;
	int length;
	while (cin >> i && i != 0) {
		int count = 0;
		int j = 3;
		int sum =  2;
		t[0] = 2;
		length = 1;

		for(;;j++) {
			if(sum > i) break;
			if(sum  + j > i && length == 1) {
				break;
			}
			if(sum + j > i) move(t,length,sum);
			if(isPrime(j)) {
				sum += j;
				if(sum > i && length <= 2) {
					break;
				}				
				if(sum == i) {				
					count ++;
					move(t,length,sum);
				}
				t[length] = j;
				length ++;
			}
		}
		if(isPrime(i))
			count ++;
		printf("%d\n",count);

		//cout << count << endl;
	}
	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