POJ 1472
来源:互联网 发布:僵尸变脸软件下载 编辑:程序博客网 时间:2024/05/29 03:42
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;char command[117];char opnum[10117];int solve(int exps[]){ memset(command, 0, sizeof(command)); scanf("%s", command); if(command[0] == 'E'){ return 0; } else if(command[0] == 'B'){ while(solve(exps)); } else if(command[0] == 'L'){ int i, t = -1; int texps[20] = {0}; scanf("%s", opnum); if(opnum[0] != 'n'){ t = atoi(opnum); } while(solve(texps)); if(t == -1){ for(i = 10; i > 0; i--){ texps[i] = texps[i - 1]; } texps[0] = 0; } else{ for(i = 0; i <= 10; i++){ texps[i] *= t; } } for(i = 0; i <= 10; i++){ exps[i] += texps[i]; } } else if(command[0] == 'O'){ scanf("%s", opnum); int t = atoi(opnum); exps[0] += t; return solve(exps); }return 1;}int main(){ int k, i, j, mflag, mcount = 1; int exps[20]; while(scanf("%d", &k) != EOF){ while(k--){ memset(exps, 0, sizeof(exps)); mflag = 0; solve(exps); printf("Program #%d\n", mcount++); printf("Runtime = "); for(i = 11; i >= 2; i--){ if(exps[i] != 0 && mflag != 0){ if(exps[i] != 1){ printf("+%d*n^%d", exps[i], i); } else{ printf("+n^%d", i); } } else if(mflag == 0 && exps[i] != 0){ mflag = 1; if(exps[i] != 1){ printf("%d*n^%d", exps[i], i); } else{ printf("n^%d", i); } } } if(exps[1] != 0 && mflag != 0){ if(exps[1] != 1){ printf("+%d*n", exps[1]); } else{ printf("+n"); } } else if(exps[1] != 0 && mflag == 0){ mflag = 1; if(exps[1] != 1){ printf("%d*n", exps[1]); } else{ printf("+n"); } } if(exps[0] != 0 && mflag != 0){ printf("+%d", exps[0]); } else if(exps[0] != 0 && mflag == 0){ mflag = 1; printf("%d", exps[0]); } if(mflag == 0){ printf("0"); } printf("\n\n"); } }return 0;}
递归模拟,代码写的很烂还参考了网上的=_=
0 0
- POJ 1472
- POJ 1472
- Poj 1472 Instant Complexity
- POJ 1472 Instant Complexity
- POJ 1472 Instant Complexity
- POJ 1472 Instant Complexity
- Poj 1472 Instant Complexity
- poj-1472 Instant Complexity
- poj 1472 Instant Complexity
- poj 1472 Instant Complexity
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- C++ lambda表达式权威指南
- PHP Static关键字
- 一些工具
- 显示数据的方法。
- C++ Primer 【第四版】第一章 快速入门
- POJ 1472
- cxf webservice + srping 整合 + 限制IP地址 + properties配置文件
- magento get sql profile
- 华尔街日报确认苹果将在9月9日发布新版iPhone
- 二叉树的后续遍历序列
- add Redo logs/dorp redo logs in Physical Standby
- cocos2d 3.2 生成Android项目文件问题 Invalid APP_STL value: c++_static
- 使用GIT进行源码管理——GIT托管服务
- 【转】Android BLE开发之Android手机与BLE终端通信