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 ...
随机推荐
- Ubuntu samba 安装与配置 实现windows和虚拟机中的Ubuntu共享文件
2. 安装sumba服务 sudo apt-get install samba samba-common 这里出现了小问题, Ubuntu上安装samba不能安装的问题,“下列的软件包有不能满足 ...
- 动态规划:HDU1059-Dividing(多重背包问题的二进制优化)
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 笔记-python-standard library-19.2 json
笔记-python-standard library-19.2 json 1. JSON简介 JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级 ...
- NOI p 2017 TG游记
嗨小朋友们大家好 还记得我是谁吗 对了我就是为iot配音的演员 弹鸡鸡 今天呐我特别的要向长沙市的oier们 洛谷的oier们 还有cnblogs的oier们问声好 为什么呢 因为我们在2017年11 ...
- Sql获取数据表字段说明
SELECT Sysobjects.name AS TABLE_NAME , syscolumns.Id , syscolumns.name AS COLUMN_NAME , systypes.nam ...
- 虚拟机VMware安Mac OS时没有Apple mac选项
相信大家很多人在虚拟机安装mac os时候发现在选择客户机操作系统时候,没有Apple mac os选项,这样就会导致无法进行下一步,下面我来给大家详细介绍怎么添加这一项. 1.首先安装unlocke ...
- python 学习分享-面向对象
好激动,学了四个月的面向对象,我终于勉勉强强的把作业做完了,现在来重构我的面向对象的知识! 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 ...
- Python学习-day15-JavaScript
JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一.如何编写 1.J ...
- LeetCode668马在棋盘上的概率
已知一个 NxN 的国际象棋棋盘,棋盘的行号和列号都是从 0 开始.即最左上角的格子记为 (0, 0),最右下角的记为 (N-1, N-1). 现有一个 “马”(也译作 “骑士”)位于 (r, c) ...
- [问题解决]docker启动不了
问题描述:昨天下午整合了同事的代码,发现docker启动好后,docker ps查看不到,docker ps -a发现docker容器没有启动. 尝试多次启动发现都是启动不了. 经过搜索发现 http ...