STL A - ACboy needs your help again!

ACboy was kidnapped!!
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!

Input

The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.

Output

For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.


男孩被绑架了!!
他非常想念他母亲,现在很害怕。你无法想象他被关进的房间有多黑暗,如此可怜: (。
作为一个聪明的ACMer,你想让ACboy走出怪物的迷宫。但是当你到达迷宫门口时,主教说:“我听说你很聪明,但是如果不能解决我的问题,你会和一个男孩一起死去。"
墙上显示了怪物的问题:
每个问题的第一行是整数N (命令的数量),以及单词“FIFO”或“FILO”。(你很高兴,因为你知道“FIFO”代表“先进先出”,而“FILO”代表“先进先出”)。
下面的N行中,每一行都是“IN M”或“OUT”( M代表整数)。
一个问题的答案是一扇门的通道,所以如果你想拯救一个男孩,请仔细回答这个问题!
投入
输入包含多个测试用例。
第一行有一个整数,代表最常见的情况。
和每个子问题的输入如上所述。
输出
对于每个命令“OUT”,您应该根据单词“FIFO”或“FILO”输出一个整数,或者如果没有任何整数,则输出一个单词“None”。

 


题意即为 :① 输入数字 t 即 IN或OUT 共t个操作  FIFO(先入先出)或FILO(先入后出)

                   ② IN 数字    或   OUT

                    根据前面操作 得到输出


Sample Input

4
4 FIFO
IN 1
IN 2
OUT
OUT
4 FILO
IN 1
IN 2
OUT
OUT
5 FIFO
IN 1
IN 2
OUT
OUT
OUT
5 FILO
IN 1
IN 2
OUT
IN 3
OUT

Sample Output

1
2
2
1
1
2
None
2
3

 


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a[10000],b[10000];
char x[10],y[10];
int main()
{
    int t;
    scanf("%d",&t);  //t个例子;
    while(t--)
    {
        int n, m;
        int i1, i2, i3;
        scanf("%d%s",&n,x);  //n个操作,x 先入先出或先入后出;
        if(!strcmp(x,"FILO"))//如果为先入后出
        {
            i1=i2=0;
            while(n--)
            {
                scanf("%s",y);  //输入字符y;
                if(!strcmp(y,"IN")) //如果y为IN,则输入数字m, 并将数字m放入数组a[]中;
                {
                    scanf("%d",&m);
                    a[i1++]=m;
                }
                else                //如果y为OUT,
                {
                    if(i1==0)         //如果i1=0,即说明a[]数组里没有存放m,输出None;
                        printf("None\n");
                    else              //否则输出刚才也就是最后 存入的m,即a[I-1],且在输出后记得i1--;
                    {
                        printf("%d\n",a[i1-1]);
                        i1--;
                    }
                }
            }
        }
        else if(!strcmp(x,"FIFO"))//如果为先入先出;
        {
            i1=i2=0;  //i2用于标记数组;
            while(n--)
            {
                scanf("%s",y);  //输入字符y;
                if(!strcmp(y,"IN")) //如果y为IN,则输入数字m, 并将数字m放入数组b[]中,从b[0]开始;
                {
                    scanf("%d",&m);
                    b[i1++]=m;  //存入一个,i1就指向下一个即将存入m的位置;
                }
                else               //如果y为OUT,
                {
                    if(i2>=i1)     //如果i2>=i1,即i2指向了i1还未指到的地方,还未存入数;
                        printf("None\n");
                    else           //输出b[i2],从零开始,每输出一次,i2++;
                        printf("%d\n",b[i2++]);
                }
            }
        }

    }
    return 0;
}

补充:

库函数 strcmp: 

if(strcmp(string 1, string 2)==0)

如果两者相同,则返回零; 

如果string 1 的ASCII码先出现较大者,则返回1,否则返回零。

STL分解-LSTM是一种深度学习模型,它结合了STL(Seasonal and Trend decomposition using Loess)分解和LSTM(Long Short-Term Memory)模型的特点。在这种方法中,首先使用STL分解将时间序列据分解为趋势、季节性和残差三个部分。然后,将分解后的趋势和季节性据作为LSTM模型的输入,用于预测未来的时间序列值。通过结合STL分解和LSTM模型,STL分解-LSTM模型可以更好地捕捉时间序列据的长期依赖和季节性变化,从而提高预测准确性。引用中的图7展示了ISTL-LSTM模型和STL-LSTM模型的预测结果的比较,而引用中的图6展示了不同深度学习模型(包括ISTL-LSTM,STL-LSTM,LSTM和GRU)在不同超参设置下的预测效果比较。另外,引用给出了STL分解-LSTM模型的超参设置,其中包括隐藏层、神经元量、训练迭代次、batch size、dropout率、激活函、损失函和优化器的选择。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [《一种改进的STL-LSTM模型:用于COVID-19疫情期间每日公交客流预测》](https://blog.csdn.net/zuiyishihefang/article/details/123320971)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值