Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
java用Scanner.next可以过,用nextLine报错memory limit exceedMLE代码如下: 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator