题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=305
思路:有点SQL语句的味道,测试好多数据都对,交上去就是RE,有时间改
错误代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <map> #include <cstring> #include <climits> #include <cmath> #include <cctype> const int inf = 0x7f7f7f7f;//2139062143 typedef long long ll; using namespace std; char a[320]; int cf(int begin1,int end1) { int j,k; int t1,t2; /*for(i=begin1; i<=end1; i++) { printf("%c",a[i]); } printf("\n");*/ j = 4; if(a[begin1+4] >= '0' && a[begin1+4] <= '9') { int sum = 0; while(a[begin1+j] != ',') { sum =sum * 10 + a[begin1+j] - '0'; j++; } t1 = sum; } else { //while(a[begin1+j] != ',' && a[begin1+j-1] != ')') while(true) { if(a[begin1+j] == ',' && a[begin1+j-1] == ')') break; j++; } k = j - 1; t1 = cf(begin1+4,k);//第二个参数是结束括号的位置 } j++; int l =begin1 + j; //printf(" %c\n",a[l]); //printf(" %d\n",t1); if(a[begin1+j] >= '0' && a[begin1+j] <= '9') { int sum = 0; while(a[begin1+j] != ')') { sum = sum * 10 + a[begin1+j] - '0'; j++; } t2 = sum; } else { while(a[begin1+j] != ')') { j++; } k = j; t2 = cf(l,k); } //printf("%d %d\n",t1,t2); if(a[begin1] == 'm' && a[begin1+1] == 'i' && a[begin1+2] == 'n') { //printf("小值%d\n",min(t1,t2)); return min(t1,t2); } else if(a[begin1] == 'm' && a[begin1+1] == 'a' && a[begin1+2] == 'x') { //printf("大值%d\n",max(t1,t2)); return max(t1,t2); } else { //printf("加法%d\n",t1+t2); return t1 + t2; } } int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",a); int len = strlen(a); int sum = cf(0,len-1); printf("%d\n",sum); } return 0; }把测试数据也贴上来
7 add(100,120) min(add(7,8),10) add(5,min(34,56)) add(5,min(34,56)) add(min(110,70),max(1,5)) add(min(3,max(1,max(1,2))),3) add(3,min(3,max(1,2))) add(3,min(3,max(1,add(1,1)))) add(max(3,2),min(3,max(1,add(1,1)))) add(max(3,add(2,4)),min(3,max(1,add(1,1)))) add(max(101,add(2,4)),min(30,max(1,add(21,1)))) add(100,min(0,10)) min(max(0,100),200)