# 【模拟/atoi函数】Game of Throwns stack

## 分析

### atoi函数(讲解)

sta.push(atoi(str.c_str()));

#### AC代码

#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;
typedef long long ll;

stack<int>sta;

int main()
{
string str;
int n, k;
while (cin >> n >> k)//操作次数
{
int sum = 0;
while (k--)
{
cin >> str;
if (str == "undo")
{
int oper_num = 0;
cin >> oper_num;
while (oper_num--)
sta.pop();
}
else
sta.push(atoi(str.c_str()));
}
sum = 0;
while (!sta.empty())
{
sum += sta.top();
sta.pop();
}
cout << (sum % n +n)%n << endl;
}
}

### string流

stringstream stringstr;
stringstr << str;
int tempNum = 0;
stringstr >> tempNum;
sta.push(tempNum);

#### AC代码

#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;
typedef long long ll;

stack<int>sta;

int main()
{
string str;
int n, k;
while (cin >> n >> k)//操作次数
{
int sum = 0;
while (k--)
{
cin >> str;
if (str == "undo")
{
int oper_num = 0;
cin >> oper_num;
while (oper_num--)
{
sta.pop();
}
}
else
{
stringstream stringstr;
stringstr << str;
int tempNum = 0;
stringstr >> tempNum;
sta.push(tempNum);
}
}
sum = 0;
while (!sta.empty())
{
sum += sta.top();
sta.pop();
}
cout << (sum % n +n)%n << endl;
}
}