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则把这个*和最后 ...
随机推荐
- Graphicmagick编译
为了需求给Graphicmagick加了几个支持,版本分别为mozjpeg2.1,bzip2-1.0.6,libpng-1.6.18,libwebp-0.4.3,mozjpeg-2.1,tiff-4. ...
- 2017.2.15 开涛shiro教程-第二十一章-授予身份与切换身份(一) table、entity、service、dao
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第二十一章 授予身份与切换身份(一) 1.使用场景 某个领导因为某 ...
- JSBridge深度剖析
概述 做过混合开发的人都知道Ionic和PhoneGap之类的框架,这些框架在web基础上包装一层Native.然后通过Bridge技术的js调用本地的库. 在讲JSBridge技术之前.我们来看一下 ...
- robotframework使用之元素定位动态ID方法
转自: http://blog.csdn.net/u011757108/article/details/53418671 一个弹出框所有元素ID竟然的动态的,关闭后再打开,里面的ID又变! 如下图: ...
- Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号
Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号 1. dwr的长处相对于ajax来说.. 1 2. DWR工作原理 1 3. Dwr的架构 2 4. 自己 ...
- glob (programming) and spool (/var/spool)
http://en.wikipedia.org/wiki/Glob_(programming) In computer programming, in particular in a Unix-lik ...
- spring-web中的WebDataBinder理解
Spring可以自动封装Bean,也就是说前台通过SpringMVC传递过来的属性值会自动对应到对象中的属性并封装成javaBean,但是只能是基本数据类型(int,String等).如果传递过来的是 ...
- ie6中 object doesn’t support this property or method
可能是由于方法或json中有注释,/**/或//删掉注释就可以了
- 解决php网页运行超时问题:Maximum execution time of 30 seconds exceeded
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Inetpub\wwwroot\ry.php on line 11 意 ...
- Jquery EasyUI弹出窗体
$("#btnCreate").click(function () { $("#modalwindow").html("<iframe widt ...