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

java用Scanner.next可以过,用nextLine报错memory limit exceed

Posted by Staniel at 2014-01-23 15:27:25 on Problem 1654
MLE代码如下:
import java.util.*;
public class Main{
	public static void main(String args[])
	{
		Scanner cin=new Scanner(System.in);
		int act[][]={{0,0},{1,-1},{1,0},{1,1},{0,-1},{0,0},{0,1},{-1,-1},{-1,0},{-1,1}};

		int t=cin.nextInt();
		cin.nextLine();
		String move;
		long x1,x2,y1,y2,area;
		int d;
		while((t--)!=0)
		{
			move=cin.nextLine();
			x2=y2=area=0;
			for (int index=0;index<move.length()-1;index++)
			{
				d=move.charAt(index)-'0';
				x1=x2+act[d][0];
				y1=y2+act[d][1];
				area+=(x1*y2-y1*x2);
				x2=x1;
				y2=y1;
			}
			if (area<0)
			area*=-1;
			if(area%2!=0)
           System.out.printf("%d.5\n",area/2);
			else
           System.out.printf("%d\n",area/2); 
		}
	}
}

把move=cin.nextLine()改成.next()就过了,大坑啊,有人帮解释一下为啥吗,本地测试结果相同,为什么提交后两种方法读入的会不一样?而且还是memory的错,不理解啊!

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