错了不下5次,如果不看报告估计很难想到这错误.
LLONG_MIN的相反数超过了LLONG_MAX所以就错了.
学了strtoll这个函数.
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstdlib>
#include <limits.h>
#include <cstring>
using namespace std;
const int maxn = 100;
int main(){
char str[maxn];
long long base, sign;
char opt, trash;
while(cin >> opt >> base >> str){
long long ans = strtoll(str, NULL, base);
if(opt == '-'){
if(ans == LLONG_MIN)printf("%llu\n", (unsigned long long)ans);
else printf("%lld\n", -ans);
continue;
}else if(opt == '~'){
ans = ~ans;
}else{
ans = !ans;
}
printf("%lld\n", ans);
}
return 0;
}