sdnuoj 1052. Water Problem 3 (Disgusting Robot)

Description

LG is a girl, this is well known to everyone,
but lg has a bad taste, no one may know.
Okay, since no one knows, let’s
forget it. LG has robots that can move according to the instructions of the remote control. The
specific instructions are as follows:
H& *^kf30pq Robot walk one step
f03u5klfj# The robot walks two steps
lsuf9823ur The robot walks three steps
skhf9832ht The robot walks four steps
jdsifu9w8e The robot returns to the starting point
%^Ihdfskjf The robot starts to explode countdown
# %^%^cxk Countdown to the end of the robot
detonation KaTeX parse error: Expected'EOF', got'#' at position 1: #̲%^# tids robot launches self-
detonation 98dfgoier# The robot randomly ran to a certain corner
when the robot started the countdown It will automatically explode after executing 10 other non-finishing or self-detonation commands.
If self- detonation is activated, it will explode directly. If the robot receives an order to randomly run to a certain corner, it will not find its position.
Now the remote control is in the hands of syc , Lg wants to take its robot back, but he only has the instruction set of syc, so please judge whether the robot can be recovered

Input

Related instructions

Output

If lg can know exactly how many steps the robot took, and the robot did not explode, it can be retrieved and output Y, otherwise output N

Sample Input

Insert picture description here

Sample Output

AND

Question: Give you relevant instructions to determine whether you can find the robot without exploding and knowing the specific number of steps

Pit: There are too many instructions, dazzling, and if you directly judge a very long string, it will time out (there are two methods, one is to use map, the other is the first letter of the string I will use next, which can greatly reduce the comparison characters String time). There is also the problem of running and losing, which requires careful analysis. Then there are many variables used in judgment, which are more complicated, so you have to distinguish them.

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <sstream>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

const int M = (int)1e7;
const int N = (int)1e5;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)998244353;
//map 用法如下
//mp <string, int> tr;
//
//tr["H"] = 1;//走一步
//tr["f03u5klfj#"] = 2;//走两步
//tr["lsuf9823ur"] = 3;//走三步
//tr["skhf9832ht"] = 4;//走四步
//tr["jdsifu9w8e"] = 0;//回到起点
//tr["%^Ihdfskjf"] = 5;//开始
//tr["#$%^%$^cxk"] = 6;//结束
//tr["$#%^#$tids"] = 7;//爆炸
//tr["98dfgoier#"] = 8;//跑了

int zou = 0;//看看开始走了没有
int num = 0;//计算一下有没有到十个指令
int ans = 0;//如果num满10 ,则赋1,或者爆了也赋1,
int pao = 0;//看看跑丢了没,跑了就赋0,回到起点就赋1

int main()
{
    
    
    string s, ss;
    while(cin>>s)
    {
    
    
        if(s[0] == 'H' || s[0] == 'f' || s[0] == 'l' || s[0] == 's')//判断首字母
        {
    
    
            if(zou)//如果之前开始走了,则zou = 1,所以可以进行这个语句,让num++
                num++;

        }
        else if(s[0] == 'j')//回到起点
        {
    
    

            pao = 0;//这个赋0是因为可能出现先跑丢,然后又跑回原点的情况,这个时候就能收回
            if(zou)
                num++;

        }
        else if(s[0] == '%')//开始
        {
    
    
            zou = 1;
        }
        else if(s[0] == '#')//终止爆炸
        {
    
    
           // k = 1;//终止爆炸,如果没跑丢,这个东西我本来想单独开一个是否爆炸,和不爆炸的,后来发现可以和ans合在一起,就省了
            zou = 0;
            num = 0;
        }
        else if(s[0] == '$')//爆炸
        {
    
    
            ans = 1;
        }
        else if(s[0] == '9')
        {
    
    
            pao = 1;
        }
        if(num == 10)
        {
    
    
            ans = 1;
        }
    }
        if(ans == 1 || pao == 1)
        {
    
    
            cout<<"N"<<endl;
        }
        else if(ans == 0 && pao == 0)
        {
    
    
            cout<<"Y"<<endl;
        }

        return 0;
}














There is another pitfall, that is, there are not enough ten in this example. When you run it, you need to change the line and press Ctrl+z, and then run

Guess you like

Origin blog.csdn.net/weixin_51216553/article/details/109889582