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则把这个*和最后 ...
随机推荐
- Web攻防之XSS,CSRF,SQL注入(转)
摘要:对Web服务器的攻击也可以说是形形色色.种类繁多,常见的有挂马.SQL注入.缓冲区溢出.嗅探.利用IIS等针对Webserver漏洞进行攻击.本文结合WEB TOP10漏洞中常见的SQL注入,跨 ...
- 负样本采样及bias校准、ctr平滑
参考:https://zhuanlan.zhihu.com/p/31529643 在CTR预估中,负样本采样是一种常见的特征工程方法.一般CTR预估的原始正负样本比可能达到1:1000~1:10000 ...
- df、du、fdisk:Linux磁盘管理
磁盘是Linux系统中一项非常重要的资源,如何对其进行有效的管理直接关系到整个系统的性能问题.对Linux磁盘管理稍微有一些学习和经验的朋 友们应该都知道df.du和fdisk这三个常用命令:df用于 ...
- git工程迁移(修改提交服务器地址)方法
git remote set-url [--push] <name> <newurl> [<oldurl>]git remote set-url --add [-- ...
- Command terminated by signal 11
Command terminated by signal 11可能的情况之中的一个是数组越界.你在訪问不被同意的内存空间.
- Solidworks如何开启自动求解
1 我打开了一个DWG格式的文件,提示草图太大,关闭的自动求解(就是没法撤销了) 2 工具-草图设定-自动求解 3 随便做一个标注,然后发现撤销按钮可以使用了,点击之后也的确可以撤销刚才的操作 ...
- 服务器,数据库连接注意mysql的user表
update user set host='localhost' where user='root';
- 日历插件js,jquery
常用的日历插件 DatePicker My97DatePicker 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing 欢迎关注,有问题一起学习欢迎留言. ...
- PHP通过prepare执行查询取得数据
可以用来防止sql注入 <?php $pdo=new PDO("mysql:host=localhost;dbname=itest", 'root',''); //先构建查询 ...
- Mysql 5.7.18 加密连接mysql_ssl_rsa_setup
MySQL 5.7.18 下载地址: https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64. ...