天天看点

ZOJ-1402

import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int count = sc.nextInt();

		while (count != 0)
		{
			int[] array = new int[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = sc.nextInt();
			}

			if (count == 1)
				System.out.println("No equal partitioning.");

			int s = 0;
			int e = array.length - 1;
			int sam = array[0];
			int ella = array[e];

			while (s != e)
			{
				if (sam > ella)
				{
					e--;
					if (e == s)
					{
						System.out.println("No equal partitioning.");
						break;
					}
					else
						ella += array[e];
				}
				else if (sam < ella)
				{
					s++;
					if (e == s)
					{
						System.out.println("No equal partitioning.");
						break;
					}
					else
						sam += array[s];
				}
				else
				{
					if (e - s == 1)
					{
						System.out.format("Sam stops at position %d and Ella stops at position %d.\n", s + 1, e + 1);
						break;
					}
					else
					{
						s++;
						sam += array[s];
					}
				}
			}

			count = sc.nextInt();
		}
	}
}
           
zoj