笨蛋的难题(一)

来源:互联网 发布:ubuntu grub 命令 编辑:程序博客网 时间:2024/04/27 02:22

笨蛋的难题(一)

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述
       笨蛋之所以称为笨蛋,是因为他有点路痴。他一旦不高兴,就必然一个人漫无目的的出去走走。今天下雨了,他又不高兴了,怎么办?那就出去走呗,这不又丢了,这次幸好记下出来时的方向,并且在一张纸上密密麻麻的记下了他拐的弯(他很聪明吧,拐的弯都是90度的弯),0代表左拐,1代表右拐,那么多0、1,他实在看不下去了,正好遇见善良加聪明的你,你能告诉他,他现在面向哪吗?
输入
多组测试数据
第一行
输入:他开始时的面对方向,和他拐弯次数n(0<n<100)。
接着n行数字表示拐的弯。
输出
他现在所面向的方向(West,East,North,South)
样例输入
East  10North   11
样例输出
NorthEast

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String toward[] = { "West", "North", "East", "South" };while (scanner.hasNext()) {String start = scanner.next();int number = scanner.nextInt();int flag = 0;for (int i = 0; i < 4; i++) {if (start.equals(toward[i])) {flag = i;break;}}for (int i = 0; i < number; i++) {int temp = scanner.nextInt();if (temp == 0) {if (flag == 0) {flag = 3;} else {flag--;}} else {if (flag == 3) {flag = 0;} else {flag++;}}}System.out.println(toward[flag]);String cc = scanner.nextLine();}}}


原创粉丝点击