UVa 12503-robot Instructions

Source: Internet
Author: User
Tags strcmp

Topic: A robot, standing at the origin of a dimension axis, has a series of instructions, divided into: left one, right one, and step i the same;

Ask the last place.

Analysis: Simulation. Direct simulation can be.

The original position is 0, left-1, right +1, calculate the number and can.

stating: ╮(╯▽╰)╭.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int  Step[101];char temp[101];int main () {int T,n,same;while (~  scanf ("%d", &t)) while (T--) {scanf ("%d", &n), for (int i = 1; I <= n; + + i) {scanf ("%s", temp); if (!strcmp (temp, "left")) step[i] = -1;else if (!strcmp (temp, "right")) step[i] = 1;else {scanf ("%s%d", &temp,&same); Step[i] = step[ Same];}} int x = 0;for (int i = 1; I <= n; + + i) x + = Step[i];p rintf ("%d\n", x);}    return 0;}


UVa 12503-robot Instructions

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.