Wed, 06 Mar 2019 13:42:26 +0800

master
大蒟蒻 7 years ago
parent b27d24cb29
commit d517910ece

@ -20,7 +20,7 @@
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{

@ -2,7 +2,116 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
char line[1 << 10 | 1], buf[1 << 10 | 1], lastop[10];
int mp[1 << 8];
void init()
{
for (char ch = '0'; ch <= '9'; ch++)
mp[ch] = ch - '0';
for (char ch = 'A'; ch <= 'Z'; ch++)
mp[ch] = ch - 'A' + 10;
for (char ch = 'a'; ch <= 'z'; ch++)
mp[ch] = ch - 'a' + 10;
for (int i = 0; i <= 9; i++)
mp[i] = i + '0';
for (int i = 10; i <= 35; i++)
mp[i] = i - 10 + 'A';
}
long long atoi(const char *str, int radix)
{
long long ret = 0;
while (*str)
ret = ret * radix + mp[*str++];
return ret;
}
void itoa(long long val, char *str, int radix)
{
int len = 0;
for (; val; val /= radix)
str[len++] = mp[val % radix];
str[len] = 0;
for (char *p1 = str, *p2 = str + len; p1 < p2;)
swap(*p1++, *--p2);
}
int main()
{
init();
int n, curBase = 10;
long long curNum = 0;
scanf("%d", &n);
while (n--)
{
do
fgets(line, 1 << 10 | 1, stdin);
while (strlen(line) < 3);
do
{
if (memcmp(line, "NUM", 3) == 0)
{
sscanf(line, "%*s%s", buf);
long long val = atoi(buf, curBase);
do
{
if (memcmp(lastop, "RST", 3) == 0)
{
curNum = val;
break;
}
if (memcmp(lastop, "ADD", 3) == 0)
{
curNum += val;
break;
}
if (memcmp(lastop, "SUB", 3) == 0)
{
curNum -= val;
break;
}
if (memcmp(lastop, "MUL", 3) == 0)
{
curNum *= val;
break;
}
if (memcmp(lastop, "DIV", 3) == 0)
{
curNum /= val;
break;
}
if (memcmp(lastop, "MOD", 3) == 0)
{
curNum %= val;
break;
}
} while (false);
break;
}
if (memcmp(line, "ADD", 3) == 0 ||
memcmp(line, "SUB", 3) == 0 ||
memcmp(line, "MUL", 3) == 0 ||
memcmp(line, "DIV", 3) == 0 ||
memcmp(line, "MOD", 3) == 0)
{
sscanf(line, "%s", lastop);
break;
}
if (memcmp(line, "CHANGE", 6) == 0)
{
sscanf(line, "%*s%s", buf);
curBase = atoi(buf, 10);
break;
}
if (memcmp(line, "EQUAL", 5) == 0)
{
itoa(curNum, buf, curBase);
puts(buf);
break;
}
if (memcmp(line, "CLEAR", 5) == 0)
{
strcpy(lastop, "RST");
break;
}
} while (false);
}
return 0;
}

Loading…
Cancel
Save