move 2
turn right
move 3
turn right
move 6

初始位置为(0,0),方向为north,求最后的位置。

string2char:  const char* t = second.c_str();

string2int:    #include <sstream>   string second;  cin>>second;  int steps;  stringstream(second)>>steps;

#include <iostream>
#include <string>
#include <sstream>
using namespace std; int main()
{
int direction[] = {,,,}; //north,east,south,west
int x_weight[] = {,,,-}; //if 0 north then 0,if 1 east then 1
int y_weight[] = {,,-,}; string action;
string second;
int x_distance = ;
int y_distance = ; int direction_present = ;
while(cin>>action>>second)
{
if(action == "move")
{
int steps;
stringstream(second)>>steps;
x_distance += x_weight[direction_present]*steps;
y_distance += y_weight[direction_present]*steps;
}
else
{
if(second == "left")
direction_present = (direction_present + ) % ;
else
direction_present = (direction_present + ) % ;
}
}
cout<<x_distance<<","<<y_distance<<endl;
return ;
}

interview ms1 robert move **的更多相关文章

  1. interview ms1 N_Dorm

    判断是否为n回文,比如 a b a 是1 回文, abcdab是2回文. 输入: abcabc|3 这种格式,输出true or false #include <iostream> #in ...

  2. [转]Design Pattern Interview Questions - Part 4

    Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...

  3. Algorithms, Part I by Kevin Wayne, Robert Sedgewick

    Welcome to Algorithms, Part I 前言 昨天在突然看到了Coursera上Robert Sedgewick讲的Algorithms,Part II看了一些,甚是爽快,所以又去 ...

  4. Google Interview University - 坚持完成这套学习手册,你就可以去 Google 面试了

    作者:Glowin链接:https://zhuanlan.zhihu.com/p/22881223来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 原文地址:Google ...

  5. Verilog Tips and Interview Questions

    Verilog Interiew Quetions Collection :  What is the difference between $display and $monitor and $wr ...

  6. Morgan Stanley telephone interview

    Today is Monday, April 28. I get a telephone call from Morgan Stanley in Shanghai. My examiner is a ...

  7. 5 Common Interview Mistakes that Could Cost You Your Dream Job (and How to Avoid Them)--ref

    There have been many articles on our site on software testing interviews. That is because, we, as IT ...

  8. English interview!

    Q1:Why are you interested in working for our company?为什么有兴趣在我们公司工作?A1:Because your company has a goo ...

  9. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

随机推荐

  1. I miss you, Jenny【我想念你,jenny】

    I miss you, Jenny Forrest Gump: 阿甘正传 You died on a Saturday morning. And I had you placed here our t ...

  2. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  3. Java并发模型框架

    构建Java并发模型框架 Java的多线程特性为构建高性能的应用提供了极大的方便,但是也带来了不少的麻烦.线程间同步.数据一致性等烦琐的问题需要细心的考虑,一不小心就会出现一些微妙的,难以调试的错误. ...

  4. 网络流24题:P2762 太空飞行计划问题

    P2762 太空飞行计划问题 题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,E ...

  5. python协程--yield和yield from

    字典为动词“to yield”给出了两个释义:产出和让步.对于 Python 生成器中的 yield 来说,这两个含义都成立.yield item 这行代码会产出一个值,提供给 next(...) 的 ...

  6. PostgreSql基础命令及问题总结

    本章内容: 1.基本命令 基本命令 1.psql -U cdnetworks_beian -d cdnetworks_beian         #-U指定用户,-d指定数据库 2.\l        ...

  7. var、let、const与JavaScript变量/常量的定义

    早期的JavaScript中,声明变量只能使用var关键字定义变量,并没有定义常量的功能.通过var关键字定义的变量,其作用域只能函数级或是全局作用域,并没有块级作用域.ES6(ECMAScript ...

  8. python实现删除空文件夹 附源代码

    前言:空文件夹虽然不占空间,但是有时候看着确实挺烦的(别误会,我不是强迫症!),所以写了一个用于删除当前目录下的空文件夹的小程序 环境:win7 64位:python2.7:IDE pycharm20 ...

  9. 集训队日常训练20181117 DIV2

    大佬们一顿操作猛如虎,拼命AC强啊 4262: 区间异或  Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByteTotal ...

  10. VMSAv8-64 translation table format descriptors

    通常情况下,一个 descriptor 可能是以下的几种 entry: 非法或者异常的 entry. Table entry, 指向 next-level translation table. Blo ...