POJ 1473 There's Treasure Everywhere!(简单几何)
来源:互联网 发布:淘宝答题在哪 编辑:程序博客网 时间:2024/04/29 20:56
There's Treasure Everywhere!
博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40865611
题目大意:
给你一个字符串,里面有许多的操作,前面的数字是移动的距离,后面的英文表示移动的方向,问最后从远点出发的一个点回落在什么地方以及距离出发点的距离是多少。
解题思路:
题目本身并不是很难,也没有什么坑点,没什么好说的,字符串处理的时候细心一点就行。
PS:每组后面需要加一个回车,因为这个PE了一次啊啊啊啊!
代码:
#include <stdio.h>#include <iostream>#include <algorithm>#include <string>#include <math.h>using namespace std;const double t = sqrt(2.0);int main(){ string s; int icase = 1; while(cin >> s) { if(s == "END") { break; } int num = 0; double x = 0, y = 0; for(int i = 0; i < (int)s.length()-1; ++i) { if(s[i] >= '0' && s[i] <= '9') { num = num*10+(s[i]-'0'); } else if(s[i] == ','){ num = 0; continue; } else if(s[i] == 'N' && s[i+1] == 'E') { x+=num/t, y+=num/t, i++; } else if(s[i] == 'N' && s[i+1] == 'W') { x-=num/t, y+=num/t, i++; } else if(s[i] == 'S' && s[i+1] == 'E') { x+=num/t, y-=num/t, i++; } else if(s[i] == 'S' && s[i+1] == 'W') { x-=num/t, y-=num/t, i++; } else if(s[i] == 'N') { y+=num; } else if(s[i] == 'S') { y-=num; } else if(s[i] == 'E') { x+=num; } else if(s[i] == 'W') { x-=num; } //printf("%lf %lf\n", x, y); } printf("Map #%d\n", icase++); printf("The treasure is located at (%.3lf,%.3lf).\n", x, y); printf("The distance to the treasure is %.3lf.\n\n", sqrt(x*x+y*y)); } return 0;}
0 0
- POJ 1473 There's Treasure Everywhere!(简单几何)
- POJ 1473 There's Treasure Everywhere! 笔记
- POJ-1473 There's Treasure Everywhere!解题报告
- 百练1473:There's Treasure Everywhere!
- G - There's Treasure Everywhere!解题报告(熊禾强)
- fjnu 1957 There's Treasure Everywhere!
- UVa 587 - There's treasure everywhere!
- POJ 1066 Treasure Hunt(计算几何)
- poj 1066 Treasure Hunt 计算几何计数
- POJ 1066 Treasure Hunt --几何,线段相交
- POJ 1066Treasure Hunt 计算几何
- POJ-2504(简单几何)
- pku 1066 Treasure Hunt(计算几何)
- uva 754 - Treasure Hunt(几何)
- POJ 1066 Treasure Hunt [线段相交]【计算几何】
- POJ-1066Treasure Hunt(计算几何线段相交)
- POJ 1106 Transmitters (简单计算几何)
- POJ 2007 简单几何
- Cocos2d-x3.1及3.2实现截屏功能
- Windows下使用Lex和Yacc
- ;TITLE Reversing a String
- 闭包
- 关于 FaceBook 广告导入的用户后续支付等事件的监测
- POJ 1473 There's Treasure Everywhere!(简单几何)
- hdoj preoblem 1598 find the most comfortable road (并查集&&动态规划)
- 语言处理程序
- richface中a4j:from和ajax Button及H:button的使用
- maven学习系列之(一)—maven的安装与基本设置
- 《unix高级环境编程》进程控制——进程等待
- 自己做列车查询系统得到的一点知识,只求以后好自己看
- 复旦校长杨玉良突然离职
- 对称排序