小火山的计算能力 多校训练2(小火山专场) poj(模拟)

http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1158&pid=9

分析:一开始没注意最终结果小于2^63-1,一直想着可能有大数了。。其实还是很简单的,只要简单模拟就好,就两种运算。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define met(a, b) memset(a, b, sizeof(a))
#define maxn 300
#define INF 0x3f3f3f3f
const int MOD = 1e9+7;

typedef long long LL;
char str[maxn];

int main()
{
    int T, flag;
    long long a, b, k;


    scanf("%d", &T);

    while(T --)
    {
        scanf("%s", str);
        a = b = flag = 0;

        for(int i=0; str[i]; i++)
        {
            if(str[i]>='0' && str[i]<='9')
                a = a * 10 + str[i] - '0';
            else
            {
                if(!flag) b += a;
                else  b -= a;

                if(str[i] == '-') flag = 1;
                else flag = 0;

                a = 0;
            }
        }

        if(!flag) printf("%lld
", b+a);
        else printf("%lld
", b-a);

    }
    return 0;
}
View Code