Dongfeng Valley Early seedling __ Luo gu

Source: Internet
Author: User
Topic Description

In the fantasy township, Dongfeng Gu Yingmio is known as up to the control of high school students Zhai Witch. One day, the early seedlings finally started the latest model of Steel dam. As the latest steel dam, of course, there is a different function with the past, that is, it can walk automatically, powerful (OK, my self-respect). The new model of early seedling can be moved according to the input command, which contains the four kinds of ' E ', ' S ', ' W ' and ' N ', corresponding to four different directions, which are East, south, west and north respectively. When a command is executed, it moves a unit in the corresponding direction. As a new type of robot, nature will not simply execute a command, it can execute command string. For the input command string, each second it acts as a command. After the last command of the command string is executed, the loop is automatically started from the beginning. At 0, the early seedling placed the steel dam in the position of the (0,0) and entered the command string. She wanted to know the coordinates of the steel dam where the T-second was.
Move eastward, change the coordinate change to (x+1,y);
Moving southward, the change of coordinate changed to (X,Y-1);
Moving westward, the change of coordinate changed to (x-1,y);
Moving northward, the change of coordinate changed to (x,y+1); Input Format:

Line 1th: A string that represents the command string entered by the early seedling, guaranteeing at least 1 commands
Line 2nd: A positive integer t output format:

Line 1th: Two integers representing t seconds, Steel Dam coordinates input sample #:

Nswwnsneewn
Output Sample #:

1 3

Bare nude simulation, but the data range is very large, then add a little processing on the line, the specific processing to see Code code

#include <cstdio> #include <cstring> using namespace std;
Char s[5010];
int x,y,t;
    inline void Read (int&x) {X=0;char C=getchar (); while (c> ' 9 ' | |
    c< ' 0 ') C=getchar ();
while (c>= ' 0 ' &&c<= ' 9 ') X=10*x+c-48,c=getchar ();
    int hh () {freopen ("robot.in", "R", stdin);
    Freopen ("Robot.out", "w", stdout);
    scanf ("%s", s);
    Read (t);
    int L=strlen (s);
    int cnt=0,o=l;
        while (o--) {if (cnt==l) cnt=0;
        if (s[cnt]== ' E ') x++,cnt++;
        else if (s[cnt]== ' W ') x--, cnt++;
        else if (s[cnt]== ' s ') y--, cnt++;
    else if (s[cnt]== ' N ') y++,cnt++;
    The process of the int k=t%l,p=t/l;//repetition can be omitted, its correctness makes a weak data can prove x*=p;y*=p;
        for (int i=1;i<=k;i++) {if (cnt==l) cnt=0;
        if (s[cnt]== ' E ') x++,cnt++;
        else if (s[cnt]== ' W ') x--, cnt++;
        else if (s[cnt]== ' s ') y--, cnt++;
    else if (s[cnt]== ' N ') y++,cnt++;
    printf ("%d%d\n", x,y);
return 0;
int hhh=hh (); int main () {;}

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.