一个判断程序运行结果对错计算分数的题目,有一个点就是如果当前指令的结果错误,以下的指令要根据当前指令得到的错误结果继续运算
还一个就是进制转换了
//leehaoze
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
const int INF = 1<<29;
#define INC_SAT( val ) (val = ((val)+1 > (val)) ? (val)+1 : (val))
#define ARR_SIZE( a ) ( sizeof( (a) ) / sizeof( (a[0]) ) )
#define ULL unsigned long long
int ivalue,t;
void Cut(char *s,string &A,string &B){
string tempA = "";
bool flag = false;
while(*s != '\0'){
if(*s == ' ') {
A = tempA;
flag = true;
++s;
tempA = "";
continue;
}
if(flag){
tempA += *s;
}
if(!flag){
tempA += *s;
}
++s;
}
B = tempA;
}
int Change_Hex(string A){
char *p = &A[A.length()-1];
int num = 0;
int count = 0;
while (*p != 'x'){
if(isalpha(*p)){
num += (int)pow(16,count++) * (*p - 'A' + 10);
}
else
num += (int)pow(16,count++) * (*p - '0');
--p;
}
return num;
}
int Change_Octal(string A){
char *p = &A[A.length()-1];
char *end = &A[0];
int num = 0;
int count = 0;
while (p != end){
num += (int)pow(8,count++) * (*p - '0');
--p;
}
return num;
}
int Change(string A){
char *p = &A[0];
if(*p == '0'){
if(*(p+1) == 'x'){
return Change_Hex(A);
}
else{
return Change_Octal(A);
}
}
else{
return atoi(A.c_str());
}
}
int Expect(char *order){
int temp = ivalue;
if(strlen(order) > 1) {
if (order[0] == '+') {
++ivalue;
temp = ivalue;
} else if (order[0] == '-') {
--ivalue;
temp = ivalue;
} else if (order[1] == '+') {
++ivalue;
} else if (order[1] == '-') {
--ivalue;
}
}
return temp;
}
void Update(char *order,int real_ans){
if(strlen(order) > 1) {
if (order[0] == '+') {
ivalue = real_ans;
} else if (order[0] == '-') {
ivalue = real_ans;
} else if (order[1] == '+') {
ivalue = real_ans + 1;
} else if (order[1] == '-') {
ivalue = real_ans - 1;
}
}
else{
ivalue = real_ans;
}
}
bool Input(){
int score = 0;
char ipt[10];
string A,B;
gets(ipt);
Cut(ipt,A,B);
ivalue = Change(A);
t = Change(B);
if(ivalue == 0 && t == 0)return false;
for (int i = 0; i < t; ++i) {
char ope[5];
int value;
scanf("%s %d",ope,&value);
getchar();
if(value == Expect(ope)){
++score;
}
else{
Update(ope,value);
}
}
printf("%d\n",score);
return true;
}
int main() {
#ifdef LOCAL
freopen("IN.txt", "r", stdin);
#endif
while(Input()){
}
return 0;
}