interview ms1 robert move **
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 **的更多相关文章
- interview ms1 N_Dorm
判断是否为n回文,比如 a b a 是1 回文, abcdab是2回文. 输入: abcabc|3 这种格式,输出true or false #include <iostream> #in ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- Algorithms, Part I by Kevin Wayne, Robert Sedgewick
Welcome to Algorithms, Part I 前言 昨天在突然看到了Coursera上Robert Sedgewick讲的Algorithms,Part II看了一些,甚是爽快,所以又去 ...
- Google Interview University - 坚持完成这套学习手册,你就可以去 Google 面试了
作者:Glowin链接:https://zhuanlan.zhihu.com/p/22881223来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 原文地址:Google ...
- Verilog Tips and Interview Questions
Verilog Interiew Quetions Collection : What is the difference between $display and $monitor and $wr ...
- Morgan Stanley telephone interview
Today is Monday, April 28. I get a telephone call from Morgan Stanley in Shanghai. My examiner is a ...
- 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 ...
- English interview!
Q1:Why are you interested in working for our company?为什么有兴趣在我们公司工作?A1:Because your company has a goo ...
- 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 ...
随机推荐
- A1055 The World's Richest(25 分)
A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...
- Git-起步
Git命令行 只要输入git,Git就会不带任何参数地列出它的选项和最常用的子命令. 要得到一个完整的git子命令列表,可以输入git help --all 显示版本号 git --version 每 ...
- Android广告页循环播放
摘要:项目要求做一个广告页,实现几秒更换一次广告页,下方还有指示第几张广告页,同样也支持手动左滑或右滑. 1.准备好粘贴5个有关广告页的类. ①BaseViewPager==>自定义高度的Vie ...
- 66、fastJson 解析json数据时,如果key值不同怎么处理?
在某些场景,你可能需要定制序列化输出,比如说,希望序列化采用之后采用"ID",而不是"id",你可以使用@JSONField这个Annotation. publ ...
- TortoiseSVN 同时检索多人的提交日志记录(如图操作)
- python-day3-内置函数与字符字节之间的转换
#三元运算 1 if True else 0 >>>1 1 if False else 0 >>>0 #内置函数lambda def f1(a1): return ...
- PostgreSQL 行排序详解
在查询生成输出表之后,也就是在处理完选择列表之后,你还可以对输出表进行排序. 如果没有排序,那么行将以不可预测的顺序返回(实际顺序将取决于扫描和连接规划类型和在磁盘上的顺序, 但是肯定不能依赖这些东西 ...
- 文本处理grep命令
this is a words file. words words to be , , , , , , , , , , beginning linux programming 4th edition ...
- csapp 深入理解计算机系统 csapp.h csapp.c文件配置
转载自 http://condor.depaul.edu/glancast/374class/docs/csapp_compile_guide.html Compiling with the CS ...
- 【bzoj3834】[Poi2014]Solar Panels 数论
题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...