ZOJ - 3930 Dice Notation 【模拟】
题目链接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3930
题意
给出一串字符串
如果是 ‘+’ ‘-’ ‘*’ ‘/’ 那么需要在前后分别加一个空格
如果遇到 纯数字 直接输出
如果遇到 adx 这样的
要化成 ([dx] + [dx] + [dx]) (a 个 dx)
但是要注意 x 和上面的纯数字 都可能是大数 然后 a 可以用long long 保存
还有 1dx 或者 dx 都是 输出 [dx] 两端没有括号
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = acos(-1);
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 5e4 + 5;
const int MOD = 1e9 + 7;
ll tran(string s)
{
ll ans = 0;
int len = s.size();
for (int i = 0; i < len; i++)
ans = ans * 10 + s[i] - '0';
return ans;
}
int main()
{
int T;
scanf("%d ", &T);
while (T--)
{
string s;
getline(cin, s);
int len = s.size();
string temp = "";
for (int i = 0; i < len; i++)
{
if (s[i] == ' ')
continue;
else if (s[i] == '(' || s[i] == ')')
printf("%c", s[i]);
else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/')
printf(" %c ", s[i]);
else if (isdigit(s[i]))
{
temp.clear();
temp = temp + s[i];
i++;
while (i < len && isdigit(s[i]))
temp = temp + s[i++];
if (s[i] == 'd')
{
ll num = tran(temp);
if (num != 1)
printf("(");
temp.clear();
temp = temp + "[d";
i++;
while (i < len && isdigit(s[i]))
temp = temp + s[i++];
i--;
temp = temp + ']';
int len = temp.size();
for (ll i = 0; i < num; i++)
{
cout << temp;
if (i <= num - 2)
printf(" + ");
}
if (num != 1)
printf(")");
}
else
{
i--;
cout << temp;
}
}
else if (s[i] == 'd')
{
printf("[d");
i++;
while (isdigit(s[i]) && i < len)
{
printf("%c", s[i++]);
}
i--;
printf("]");
}
}
printf(" = [Result]\n");
}
}
ZOJ - 3930 Dice Notation 【模拟】的更多相关文章
- ZOJ 3930 Dice Notation
简单模拟题.一个int写成了char,搞了4个多小时.真垃圾.. #include<stdio.h> #include<string.h> +],s[+]; +]; +]; i ...
- Dice Notation(模拟)
Dice Notation Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- ZOJ - 3829 Known Notation(模拟+贪心)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 给定一个字符串(只包含数字和星号)可以在字符串的任意位置添加一个数字 ...
- 贪心+模拟 ZOJ 3829 Known Notation
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...
- zoj 3829 Known Notation
作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...
- ZOJ 3829 Known Notation 贪心
Known Notation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showPro ...
- ZOJ 3829 Known Notation (2014牡丹江H称号)
主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...
- ZOJ 3829 Known Notation 乱搞
乱搞: 1.数字的个数要比*的个数多一个,假设数字不足须要先把数字补满 2.最优的结构应该是数字都在左边,*都在右边 3.从左往右扫一遍,遇到数字+1,遇到*-1,假设当前值<1则把这个*和最后 ...
随机推荐
- MFC中 CString转换为char
网上好多方法,比如强制转换: CString strTest = _T(“abcd”); char *buf = (LPSTR)(LPCTSTR)strTest; 可是都只得到了第一个字符. 后来,找 ...
- Oracle递归操作
需求:找出代理商中没有挂商家的代理商 简单SQL如下: select * from t_proxy tp where tp.id not in (SELECT tp.id as p_id FROM t ...
- GCC + GDB 调试方法
首先编译程序 多加一个 -g c++ test.cpp -o a -Wall -g 执行时使用 gdb a 此时输入 l 显示所有的代码 l 输入b 加入断点到某一行(break) b 108 运行 ...
- hdu 5339 Untitled【搜索】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5339 题意:一个整数a 和一个数组b.问你能否在b中取出r个元素排列组成c数组满足a%c1%c1%-. ...
- 第一个Swift程序Hello World
import Foundation print("Hello, World!") print("I am here!") var arr=["项羽&q ...
- Ubuntu系统经常使用操作指令说明
使用U盘拷贝压缩文件 文件的压缩方法详见:3.6文件归档压缩及其释放 U盘直接插入机器USB接口.等待自己主动弹出窗体,在弹出窗体选择"文件->打开终端",打开的终端当前文件 ...
- $ is not defined
$ is not defined 引入Jquery的顺序不正确,要把它放在第一个引入
- Android解析聚合数据之天气预报
免费天气预报API:https://www.juhe.cn/docs/api/id/73 ,申请APPKEY MainActivity.java <span style="font-s ...
- 以前整理的网络上免费API接口
以前整理的一些免费的API接口,具体是否好用还需要时间测试,但是先分享给大家. 天气接口 聚合数据: http://op.juhe.cn/onebox/weather/query 用例 官方文档 来源 ...
- vue-cli配置文件详解
转自: https://blog.csdn.net/Mr_YanYan/article/details/79233188