本文主要是介绍笨蛋的难题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
描述
笨蛋之所以称为笨蛋,是因为他有点路痴。他一旦不高兴,就必然一个人漫无目的的出去走走。今天下雨了,他又不高兴了,怎么办?那就出去走呗,这不又丢了,这次幸好记下出来时的方向,并且在一张纸上密密麻麻的记下了他拐的弯(他很聪明吧,拐的弯都是90度的弯),0代表左拐,1代表右拐,那么多0、1,他实在看不下去了,正好遇见善良加聪明的你,你能告诉他,他现在面向哪吗?
输入
多组测试数据
第一行
输入:他开始时的面对方向,和他拐弯次数n(0<n<100)。
接着n行数字表示拐的弯。
输出
他现在所面向的方向(West,East,North,South)
样例输入
East 1
0
North 1
1
样例输出
North
East
本来想写的巧妙一些,结果写着写着卡住了,最后成下面这样了
public static void main(String[] args){Scanner sc=new Scanner(System.in);String a=sc.next();int b=sc.nextInt();int c=sc.nextInt();if(a.equals("North")){if(b%4==1){if(c==0){System.out.println("West");}if(c==1){System.out.println("East");}}if(b%4==2){if(c==0){System.out.println("South");}if(c==1){System.out.println("South");}}if(b%4==3){if(c==0){System.out.println("East");}if(c==1){System.out.println("West");}}if(b%4==0){System.out.println("North");}}else if(a.equals("South")){if(b%4==1){if(c==0){System.out.println("East");}if(c==1){System.out.println("West");}}if(b%4==2){if(c==0){System.out.println("North");}if(c==1){System.out.println("North");}}if(b%4==3){if(c==0){System.out.println("West");}if(c==1){System.out.println("East");}}if(b%4==0){System.out.println("South");}}else if(a.equals("West")){if(b%4==1){if(c==0){System.out.println("South");}if(c==1){System.out.println("North");}}if(b%4==2){if(c==0){System.out.println("East");}if(c==1){System.out.println("East");}}if(b%4==3){if(c==0){System.out.println("North");}if(c==1){System.out.println("South");}}if(b%4==0){System.out.println("West");}}else if(a.equals("East")){if(b%4==1){if(c==0){System.out.println("North");}if(c==1){System.out.println("South");}}if(b%4==2){if(c==0){System.out.println("West");}if(c==1){System.out.println("West");}}if(b%4==3){if(c==0){System.out.println("South");}if(c==1){System.out.println("North");}}if(b%4==0){System.out.println("West");}}}
这篇关于笨蛋的难题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!