zoukankan      html  css  js  c++  java
  • 笨蛋的难题(一)

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


     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     char s[10];
     6     int n;
     7     int direction;
     8     
     9     while(scanf("%s%d",&s,&n)!=EOF){
    10         while(n--){
    11             scanf("%d",&direction);
    12             
    13             if(strcmp(s,"West")==0){
    14                 if(direction==0){
    15                     strcpy(s,"South");
    16                 }
    17                 else
    18                     strcpy(s,"North");
    19             }
    20             
    21             else if(strcmp(s,"East")==0){
    22                 if(direction==0){
    23                     strcpy(s,"North");
    24                 }
    25                 else
    26                     strcpy(s,"South");
    27             }
    28             
    29             else if(strcmp(s,"North")==0){
    30                 if(direction==0){
    31                     strcpy(s,"West");
    32                 }
    33                 else    
    34                     strcpy(s,"East");
    35             }
    36             
    37             else if(strcmp(s,"South")==0){
    38                 if(direction==0)
    39                     strcpy(s,"East");
    40                 else
    41                     strcpy(s,"West");
    42             }
    43         }
    44         printf("%s
    ",s);
    45     }
    46     return 0;
    47 }
  • 相关阅读:
    < high performance web sites > 阅读小记
    Gimp制作圆角透明图片
    iphone开发小记
    Android开发小记
    双网卡绑定(suse)
    xen虚拟机操作整理
    linux网络相关命令使用
    lua协程并发下载简单测试
    linux使用技巧(shell/vi/screen)
    爬虫之scrapy框架
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4101333.html
Copyright © 2011-2022 走看看