zoukankan      html  css  js  c++  java
  • 第一轮 B

    机器人的指令
    Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status
    
    Description
    Download as PDF
    
      Robot Instructions 
    
    You have a robot standing on the origin of x axis. The robot will be given some instructions. Your task is to predict its position after executing all the instructions.
    
        LEFT: move one unit left (decrease p by 1, where p is the position of the robot before moving)
        RIGHT: move one unit right (increase p by 1)
        SAME AS i: perform the same action as in the i-th instruction. It is guaranteed that i is a positive integer not greater than the number of instructions before this. 
    
    Input 
    The first line contains the number of test cases T ( T$ le$100). Each test case begins with an integer n ( 1$ le$n$ le$100), the number of instructions. Each of the following n lines contains an instruction.
    
    Output 
    For each test case, print the final position of the robot. Note that after processing each test case, the robot should be reset to the origin.
    
    Sample Input 
    
    2
    3
    LEFT
    RIGHT
    SAME AS 2
    5
    LEFT
    SAME AS 1
    SAME AS 2
    SAME AS 1
    SAME AS 4
    
    Sample Output 
    
    1
    -5
    
    
    Problemsetter: Rujia Liu, Special Thanks: Feng Chen, Md. Mahbubul Hasan 
    /*************************************************************************
    	> File Name: b.cpp
    	> Author: yuan 
    	> Mail: 
    	> Created Time: 2014年11月08日 星期六 18时39分01秒
     ************************************************************************/
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int str[105];
    int ans;
    int t;
    int n;
    int main()
    {
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);ans=0;
            memset(str,0,sizeof(str));
            for(int i=1;i<=n;i++)
            {
                char s[10];
                memset(s,0,sizeof(s));
                scanf("%s",s);
                if(strcmp(s,"LEFT")==0){
                    str[i]=-1;
                    ans+=str[i];
                    continue;
                }
                if(strcmp(s,"RIGHT")==0){
                    str[i]=1;
                    ans+=str[i];
                    continue;
                }
                if(strcmp(s,"SAME")==0){
                    int k;
                    scanf("%s",s);
                    scanf("%d",&k);
                    str[i]=str[k];
                    ans+=str[k];
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    


  • 相关阅读:
    异常处理机制
    如题
    MSSql随机取数据据
    在ASP.NET中下载Text文件,而不是在浏览器中打开它
    [原创]SQLite .net 数据库操作类
    对WinForm的App.config文件进行加密 转自 http://www.cnblogs.com/Jinjian/archive/2006/09/06/496009.html
    大型系统上PHP令人不爽的九大原因 转自:http://edu.itbulo.com/200705/114678.htm
    [原创]AspNetPager GridView 直连数据库 分页列子
    用.NET读取Flash格式文件信息
    js调用php动态数据
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254404.html
Copyright © 2011-2022 走看看