题目链接

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 【模拟】的更多相关文章

  1. ZOJ 3930 Dice Notation

    简单模拟题.一个int写成了char,搞了4个多小时.真垃圾.. #include<stdio.h> #include<string.h> +],s[+]; +]; +]; i ...

  2. Dice Notation(模拟)

    Dice Notation Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit  ...

  3. ZOJ 3826 Hierarchical Notation 模拟

    模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...

  4. ZOJ - 3829 Known Notation(模拟+贪心)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 给定一个字符串(只包含数字和星号)可以在字符串的任意位置添加一个数字 ...

  5. 贪心+模拟 ZOJ 3829 Known Notation

    题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...

  6. zoj 3829 Known Notation

    作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...

  7. ZOJ 3829 Known Notation 贪心

    Known Notation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showPro ...

  8. ZOJ 3829 Known Notation (2014牡丹江H称号)

    主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...

  9. ZOJ 3829 Known Notation 乱搞

    乱搞: 1.数字的个数要比*的个数多一个,假设数字不足须要先把数字补满 2.最优的结构应该是数字都在左边,*都在右边 3.从左往右扫一遍,遇到数字+1,遇到*-1,假设当前值<1则把这个*和最后 ...

随机推荐

  1. quick-cocos2d 设置横屏

    quick cocos2d新建项目,在xcode中 起模拟器,默认的是竖屏,我想做一个横屏的游戏,前面已经说了 选中你的项目,在General这个标签内,Deoployment info的这个分组,有 ...

  2. Android性能优化第(一)篇---基本概念

    最近打算总结几篇app性能优化方面的东西,毕竟android弄了这么久,万一到哪些转了行,岁月久了就忘记了,纯粹当个人笔记.今个是第一篇---性能优化的基本概念,毛主席说了,让理论先行,理论指导实践. ...

  3. supervisor开机自启动方法

    配置service类型服务 #!/bin/bash # # supervisord This scripts turns supervisord on # # Author: Mike McGrath ...

  4. .NET Core R2安装及示例教程

    .NET Core R2安装及示例教程 Install for Windows - Visual Studio 2015 1 Download Visual Studio 2015 Make sure ...

  5. VELT-0.1.5开发:在VS2013下进行python开发

    快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 本文仅适用于vs20 ...

  6. 多媒体层预览(Media Layer OverView)

    音频模块位于多媒体层里.多媒体层包含了图形.音频.视频三种技术.这三种技术会给你带来声觉.视觉上的良好体验. 来看看ios的结构体系以及媒体层上的内容:                         ...

  7. java:注解(一)

    什么是注解 注解(Annotation),也叫(metadata)元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它可以声明在包.类.字段.方法. ...

  8. SQLSERVER聚集索引和主键(Primary Key)的误区认识

    引用别人的,供以后学习使用,谢谢! 很多人会把Primary Key和聚集索引搞混起来,或者认为这是同一个东西.这个概念是非常错误的. 主键是一个约束(constraint),他依附在一个索引上,这个 ...

  9. 可以添加自定义的Select控件

    1.控件dom <select name="WebSiteTarget" id="WebSiteTarget" class="w1" ...

  10. ASP.NET MVC 扩展自定义视图引擎支持多模板&动态换肤skins机制

    ASP.NET  mvc的razor视图引擎是一个非常好的.NET  MVC 框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的 ...