HDU
来源:互联网 发布:python运维脚本优势 编辑:程序博客网 时间:2024/05/22 06:24
Arithmetic of Bomb
Problem Description
众所周知,度度熊非常喜欢数字。
它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数!
但是这回的算术题可并不简单,由于含有表示bomb的#号,度度熊称之为 Arithmetic of Bomb。
![](../../../data/images/C777-1001-1.jpg)
Bomb Number中的bomb,也就是#号,会展开一些数字,这会导致最终展开的数字超出了度度熊所能理解的范畴。比如”(1)#(3)”表示”1”出现了3次,将会被展开为”111”,
同理,”(12)#(2)4(2)#(3)”将会被展开为”12124222”。
为了方便理解,下面给出了Bomb Number的BNF表示。
```
<bomb number> := <bomb term> | <bomb number> <bomb term>
<bomb term> := <number> | '(' <number> ')' '#' '(' <non-zero-digit> ')'
<number> := <digit> | <digit> <number>
<digit> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
```
请将Bomb Number中所有的#号展开,由于数字可能很长,结果对 1 000 000 007 取模。
它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数!
但是这回的算术题可并不简单,由于含有表示bomb的#号,度度熊称之为 Arithmetic of Bomb。
![](../../../data/images/C777-1001-1.jpg)
Bomb Number中的bomb,也就是#号,会展开一些数字,这会导致最终展开的数字超出了度度熊所能理解的范畴。比如”(1)#(3)”表示”1”出现了3次,将会被展开为”111”,
同理,”(12)#(2)4(2)#(3)”将会被展开为”12124222”。
为了方便理解,下面给出了Bomb Number的BNF表示。
```
<bomb number> := <bomb term> | <bomb number> <bomb term>
<bomb term> := <number> | '(' <number> ')' '#' '(' <non-zero-digit> ')'
<number> := <digit> | <digit> <number>
<digit> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
```
请将Bomb Number中所有的#号展开,由于数字可能很长,结果对 1 000 000 007 取模。
Input
第一行为T,表示输入数据组数。
每组数据包含一个Bomb Expression。
- 1≤T≤100
- 1≤length(Bomb Number)≤1000
每组数据包含一个Bomb Expression。
- 1≤T≤100
- 1≤length(Bomb Number)≤1000
Output
对每组数据输出表达式的结果,结果对 1 000 000 007 取模。
Sample Input
41(1)#(3)(12)#(2)4(2)#(3)(12)#(5)
Sample Output
111112124222212121205
Source
2017"百度之星"程序设计大赛 - 复赛
解题思路:水题,打上几个标记就好了,然后套个大数取模模板,详细请看代码。(注意,不会有嵌套括号)
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <set>#include <vector>#include <map>#include <stack>#include <set>#include <algorithm>#include<queue>#define INF (1<<29)using namespace std;typedef long long ll;//输入外挂inline int scanf(int &num){ char in;bool IsN=false; in=getchar(); if(in==EOF) return -1; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ IsN=true;num=0;} else num=in-'0'; while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0'; } if(IsN) num=-num; return 1;}string str;int main(){ int t; scanf(t); while(t--){ cin>>str; string ans;//记录最终字符串 int zuo=1;//是输入#号左边的数还是右边的数 int zhong=0;//标记是否开始输入括号中间的数 string zhongnum;//记录#左边的数 int count=0;//记录#右边的数 for(int i=0;i<str.size();i++){ if(str[i]=='('){ zhong=1; continue; } if(str[i]==')'){ zhong=0; if(zuo==1) zuo=0; else{ zuo=1; //插入count遍 for(int k=0;k<count;k++) ans+=zhongnum; zhongnum="";//还原 } continue; } if(str[i]=='#') continue; if(zhong){ if(zuo)//看看是哪边 zhongnum.push_back(str[i]); else{ count=str[i]-'0'; } } else//直接插入 ans.push_back(str[i]); } //大数取模模板 ll MODZ=1000000007; int len = ans.size(); ll ansnum = 0; for(int i = 0; i < len; ++i){ ansnum = ansnum*10 + (ans[i]-'0'); ansnum %= MODZ; } cout<<ansnum<<endl; } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 【c++】复杂的数据类型
- 时间复杂度和空间复杂度_简单易上手
- Face2Face: Real-time Face Capture and Reenactment of RGB Videos 论文翻译
- POJ 2431 Expedition(贪心+优先队列)
- 2017百度之星复赛1001 Arithmetic of Bomb
- HDU
- 【kong系列九】之限流rate-limiting插件
- CodeForces】Gargari and Bishops
- vue项目开发配置信息
- 回溯算法解决数独
- Android 透明状态栏
- Oracle学习笔记之二
- 利用DevicePolicyManager执行屏幕锁定
- Tablayout与视频拖拽相对应