笨蛋的难题(一)

来源:互联网 发布:淘宝店策划方案 编辑:程序博客网 时间:2024/03/29 13:46

描述

      笨蛋之所以称为笨蛋,是因为他有点路痴。他一旦不高兴,就必然一个人漫无目的的出去走走。今天下雨了,他又不高兴了,怎么办?那就出去走呗,这不又丢了,这次幸好记下出来时的方向,并且在一张纸上密密麻麻的记下了他拐的弯(他很聪明吧,拐的弯都是90度的弯),0代表左拐,1代表右拐,那么多0、1,他实在看不下去了,正好遇见善良加聪明的你,你能告诉他,他现在面向哪吗?

输入

多组测试数据

第一行

输入:他开始时的面对方向,和他拐弯次数n(0<n<100)。

接着n行数字表示拐的弯。

输出

他现在所面向的方向(West,East,North,South)

样例输入

East 1

0

North  1

1

east 东south 南west 西north 北

我用NYOJ提交代码时,我以前一直提交的是这

import java.util.Scanner;public class Main {Scanner scan=new Scanner(System.in);public static void main(String[] args){Main test2=new Main();test2.start();}int c=0;public void start(){String a=scan.next();int b=scan.nextInt();    switch(a.charAt(0)){case 'W':c=1;break;case 'S':c=2;break;case 'E':c=3;break;case 'N':c=4;break;}int[] i1=new int[b];for(int i2=0;i2<i1.length;i2++){if(scan.nextInt()==0){c=(c+1);if(c==5){c=1;}}else{c=(c-1);if(c==0){c=4;}}}switch(c){case 1:System.out.println("West");break;case 2:System.out.println("South");break;case 3:System.out.println("East");break;case 4:System.out.println("North");break;}}}
只要在start里面用一个while(scan.hasNext())就可以通过。

0 0
原创粉丝点击