Rational Grading UVALive
来源:互联网 发布:网络舆情信息 编辑:程序博客网 时间:2024/05/22 13:27
一个判断程序运行结果对错计算分数的题目,有一个点就是如果当前指令的结果错误,以下的指令要根据当前指令得到的错误结果继续运算
还一个就是进制转换了
//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 longint 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;}
0 0
- Rational Grading UVALive
- Rational Grading UVALive
- Grading
- Grading
- UVALive 7363 A Rational Sequence (二叉树)
- RATIONAL
- Rational
- UVa111History Grading
- 1002. Grading
- History Grading
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- POJ-1195-二维树状数组
- Andrew Ng机器学习week4(Neural Networks: Representation)编程习题
- SSH框架整合之使用Domain Modelurl取参数值
- 美图笔试总结
- Java多线程(四)之——Lock
- Rational Grading UVALive
- POJ 1035
- Leetcode 278. First Bad Version
- 自考之路—操作系统阶段小结2
- Lintcode24 LFU Cache solution 题解
- 通过SharePreferences 记住密码
- ZOJ
- HTML
- CentOS下的Hadoop安装教程