迷路的牛牛题解

迷路的牛牛

http://www.nowcoder.com/questionTerminal/fc72d3493d7e4be883e931d507352a4a

傻瓜式思路,输入L左转,输入R右转

  • 时间复杂度
  • 空间复杂度
    #include 
    using namespace std;
    int main(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      int n = 0;
      cin>>n;
      char turn[n];
      for(int i=0; i<n; i++){
          cin>>turn[i];
      }
      char direction[] = {'N','E','S','W'};
      int direction_i = 0;
      for(int i=0; i<n; i++){
          if(turn[i] == 'R' && direction_i != 3) direction_i++;
          else if(turn[i] == 'R' && direction_i == 3) direction_i = 0;
          else if(turn[i] == 'L' && direction_i != 0)  direction_i--;
          else direction_i = 3;
      }
      cout<<direction[direction_i]<<'\n';
    }
全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
05-26 09:07
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务