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 ...
随机推荐
- Python编写一个程序求2的次方
#!/usr/bin/env python3 #-*- coding:utf-8 -*- #":"冒号后面为对参数注释,"->"为对整个函数注释 def ...
- 初学js之qq聊天展开实例
实现这样的效果. 直接看代码,html部分: <body> <div class="box"> <div class="lists" ...
- stm32串口——标志位学习
/* 在USART的发送端有2个寄存器,一个是程序可以看到的USART_DR寄存器,另一个是程序看不到的移位寄存器,对应USART数据发送有两个标志,一个是TXE=发送数据寄存器空,另一个是TC=发送 ...
- Flow Problem HDU - 3549
Flow Problem HDU - 3549 Network flow is a well-known difficult problem for ACMers. Given a graph, yo ...
- 快速排序算法(C)
sort快排函数的基本版,效率n*logn,快排的完全版就是在递归之中夹杂对序列的预判断,最优的选择排序方法,快速排序算法只是其中之一. 简单的说明一下快速排序的思想,对于一个数列,首先选择一个基数( ...
- tensorboard在cmd运行成功但在浏览器中不能正常显示的问题解决
我是配置了两个python环境,python3.5和anconda3.5,强烈建议使用python3.5版本,算是比较稳定的! cmd在运行时是按顺序查找的文件,如果说是python3.6这个版本问 ...
- OpenStack之Glance源码简析
Glance简介 OpenStack镜像服务器是一套虚拟机镜像发现.注册.检索. glance架构图: Glance源码结构: glance/api:主要负责接收响应镜像管理命令的Restful请求, ...
- IOS开发学习笔记013-内存管理
内存管理 1.基本知识 2.关闭ARC机制 3.@property 4.循环引用 5.自动释放池 6.内存管理总结 一.基本知识 内存的分类 栈:局部变量 堆:动态申请的对象,变量等 全局(静态):s ...
- python 学习分享-常用模块篇
模块 就是前人给你造的轮子,你开车就好!!! 常用模块有: time模块 random模块 os模块 sys模块 shutil模块 json & picle模块 shelve模块 xml处 ...
- SDRAM学习(一)之刷新心得
本篇博文共有两种刷新方式 SDRAM数据手册给出每隔64ms就要将所有行刷新一遍, 因此每隔64_000_000 ns/2^12=15625ns 就要刷新一次.(因为一个L-Bank的行是12位,所以 ...