POJ 1473 There's Treasure Everywhere! (Simple ry)

Source: Internet
Author: User

There's Treasure Everywhere!


Blog original address: http://blog.csdn.net/xuechelingxiao/article/details/40865611


Question:

Here is a string with many operations. The preceding number is the moving distance, and the following English indicates the moving direction, ask where the last point of departure from the distant point falls and the distance from the starting point.


Solution:

The question itself is not very difficult, and there is no pitfall, nothing to say, just be careful when dealing with strings.

PS: a carriage return is required for each group, because this PE is used once!


Code:

# 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 \ 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 ", sqrt (x * x + y * y);} return 0 ;}


POJ 1473 There's Treasure Everywhere! (Simple ry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.