华为oj 坐标移动
来源:互联网 发布:2016淘宝网店开店流程 编辑:程序博客网 时间:2024/04/29 05:06
开发一个坐标计算工具, A表示向左移动,D表示向右移动,W表示向上移动,S表示向下移动。从(0,0)点开始移动,从输入字符串里面读取一些坐标,并将最终输入结果输出到输出文件里面。
输入:
合法坐标为A(或者D或者W或者S) + 数字(两位以内)
坐标之间以;分隔。
非法坐标点需要进行丢弃。如AA10; A1A; $%$; YAD; 等。
下面是一个简单的例子 如:
A10;S20;W10;D30;X;A1A;B10A11;;A10;
处理过程:
起点(0,0)
+ A10 = (-10,0)
+ S20 = (-10,-20)
+ W10 = (-10,-10)
+ D30 = (20,-10)
+ x = 无效
+ A1A = 无效
+ B10A11 = 无效
+ 一个空 不影响
+ A10 = (10,-10)
结果 (10, -10)
知识点 字符串
运行时间限制 0M
内存限制 0
输入
一行字符串
输出
最终坐标,以,分隔
样例输入 A10;S20;W10;D30;X;A1A;B10A11;;A10;
样例输出 10,-10
输入:
合法坐标为A(或者D或者W或者S) + 数字(两位以内)
坐标之间以;分隔。
非法坐标点需要进行丢弃。如AA10; A1A; $%$; YAD; 等。
下面是一个简单的例子 如:
A10;S20;W10;D30;X;A1A;B10A11;;A10;
处理过程:
起点(0,0)
+ A10 = (-10,0)
+ S20 = (-10,-20)
+ W10 = (-10,-10)
+ D30 = (20,-10)
+ x = 无效
+ A1A = 无效
+ B10A11 = 无效
+ 一个空 不影响
+ A10 = (10,-10)
结果 (10, -10)
知识点 字符串
运行时间限制 0M
内存限制 0
输入
一行字符串
输出
最终坐标,以,分隔
样例输入 A10;S20;W10;D30;X;A1A;B10A11;;A10;
样例输出 10,-10
分析:
熟悉字符串处理
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s,tmp,move_str;
int move_num;
getline(cin,s);
int x=0,y=0,pos=0;
while(!s.empty())
{
pos=s.find(';');
tmp=s.substr(0,pos);
s=s.substr(pos+1);
if(tmp.size()>=2&&tmp.size()<=3)
{
move_str=tmp.substr(1);
move_num=atoi(move_str.c_str());
if((tmp.size()==2&&isdigit(move_str[0]))||(tmp.size()==3&&isdigit(move_str[0])&&isdigit(move_str[1])))
{
if(tmp[0]=='A')
x-=move_num;
else if(tmp[0]=='S')
y-=move_num;
else if(tmp[0]=='W')
y+=move_num;
else if(tmp[0]=='D')
x+=move_num;
}
}
}
cout<<x<<","<<y<<endl;
//system("pause");
return 0;
}
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s,tmp,move_str;
int move_num;
getline(cin,s);
int x=0,y=0,pos=0;
while(!s.empty())
{
pos=s.find(';');
tmp=s.substr(0,pos);
s=s.substr(pos+1);
if(tmp.size()>=2&&tmp.size()<=3)
{
move_str=tmp.substr(1);
move_num=atoi(move_str.c_str());
if((tmp.size()==2&&isdigit(move_str[0]))||(tmp.size()==3&&isdigit(move_str[0])&&isdigit(move_str[1])))
{
if(tmp[0]=='A')
x-=move_num;
else if(tmp[0]=='S')
y-=move_num;
else if(tmp[0]=='W')
y+=move_num;
else if(tmp[0]=='D')
x+=move_num;
}
}
}
cout<<x<<","<<y<<endl;
//system("pause");
return 0;
}
0 0
- 华为oj 坐标移动
- 华为OJ 坐标移动
- 华为oj 坐标移动
- 华为Oj 坐标移动
- 华为oj 坐标移动
- 华为oj--坐标移动
- 华为OJ----坐标移动
- 华为OJ(坐标移动)
- 【华为OJ】【016-坐标移动】
- 华为 OJ 坐标的移动
- 华为oj中级 坐标移动
- 华为OJ中级题-.坐标移动
- 华为OJ——坐标移动
- 华为OJ——坐标移动
- 华为测试 坐标移动
- 【OJ中级】坐标移动
- OJ------坐标移动
- 华为机试题:坐标移动
- 从头认识java-特辑-你不知道的main函数
- [剑指offer]用两个栈实现队列
- spring 手动事务回滚
- 下一个排列
- ubuntu下配置JDK7环境变量
- 华为oj 坐标移动
- javax.mail.AuthenticationFailedException异常
- 时钟周期/指令周期/机器周期/总线周期+系统时钟,CPU时钟
- 招聘需求系列之七
- 03@设计模式-(01)工厂模式
- java Thread sleep yield join wait notify notifyAll
- Atitit. http 代理原理 atiHttpProxy 大木马
- HDU 2181 哈密顿绕行世界问题
- Android中framework层的cpp文件中调用native层c函数的方法