题目链接

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. weblogic的集群与配置图文

      一.Weblogic的集群 还记得我们在第五天教程中讲到的关于Tomcat的集群吗? 两个tomcat做node即tomcat1, tomcat2,使用Apache HttpServer做请求派发 ...

  2. spring boot 读取配置文件(application.yml)中的属性值

    在spring boot中,简单几步,读取配置文件(application.yml)中各种不同类型的属性值: 1.引入依赖: <!-- 支持 @ConfigurationProperties 注 ...

  3. Android 百度地图开发(二)

    这一篇文章主要解说的是百度地图的定位功能,然后还有MyLocationOverlay和PopupOverlay两个地图覆盖物的使用.Overlay是"图层"或"覆盖物&q ...

  4. js函数的Json写法

    https://zhidao.baidu.com/question/83401454.html

  5. C语言-字符串

    问题: 给出的区分大小写的字母字符的字符串,找到最大的字符串X,或者为X,或者其逆可以找到任何给定的字符串的子串 输入: 输入文件的第一行包含一个整数t(1 < = t < = 10),测 ...

  6. Redis学习手册(List数据类型)(转)

    一.概述: 在Redis中,List类型是按照插入顺序排序的字符串链表.和数据结构中的普通链表一样,我们可以在其头部(left)和尾部(right)添加新的 元素.在插入时,如果该键并不存在,Redi ...

  7. 淘宝数据库OceanBase SQL编译器部分 源代码阅读--解析SQL语法树

    OceanBase是阿里巴巴集团自主研发的可扩展的关系型数据库,实现了跨行跨表的事务,支持数千亿条记录.数百TB数据上的SQL操作. 在阿里巴巴集团下,OceanBase数据库支持了多个重要业务的数据 ...

  8. 为什么阿里巴巴不建议在for循环中使用"+"进行字符串拼接

    字符串,是Java中最常用的一个数据类型了.关于字符串的知识,作者已经发表过几篇文章介绍过很多,如: Java 7 源码学习系列(一)--String 该如何创建字符串,使用" " ...

  9. 微服务之旅:从Netflix OSS到 Istio Service Mesh

    在这篇文章中,我们从Netflix开始,通过Envoy和Istio的崛起,快速浏览微服务的历史. 微服务是具有边界上下文的松散耦合服务,使您能够独立开发,部署和扩展服务.它还可以定义为构建独立开发和部 ...

  10. hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

    hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibern ...