2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】
Arithmetic of Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 129 Accepted Submission(s): 94
它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数!
但是这回的算术题可并不简单,由于含有表示bomb的#号,度度熊称之为 Arithmetic of Bomb。

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 取模。
每组数据包含一个Bomb Expression。
- 1≤T≤100
- 1≤length(Bomb Number)≤1000
4
1
(1)#(3)
(12)#(2)4(2)#(3)
(12)#(5)
1
111
12124222
212121205
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner; import javax.print.attribute.Size2DSyntax; public class Main { /**
* @param args
*/
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int mod=1000000007;
while(in.hasNextInt())
{
int T=in.nextInt();
for(int a=1;a<=T;a++)
{
String s=in.next();
long ans=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='(')
{
int pos;
for(int j=i;;j++)
{
if(s.charAt(j)==')')
{
pos=j;
break;
}
}
int num=(s.charAt(pos+3)-'0');
for(int k=0;k<num;k++)
{
for(int l=i+1;l<pos;l++)
{
ans=(ans*10+s.charAt(l)-'0')%mod;
}
}
i=pos+4;
}
else
ans=(ans*10+s.charAt(i)-'0')%mod;
}
System.out.println(ans);
} }
} }
2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】的更多相关文章
- 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】
Valley Numer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】
Pokémon GO Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 2017"百度之星"程序设计大赛 - 复赛 01,03,05
Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [SinGuLaRiTy] 2017 百度之星程序设计大赛 复赛
[SinGuLaRiTy-1038] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. Arithmetic of Bomb Problem D ...
- 【2017"百度之星"程序设计大赛 - 复赛】Arithmetic of Bomb
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=777&pid=1001 [题意] 在这里写 [题解] ...
- 2017百度之星程序设计大赛 - 复赛 Arithmetic of Bomb
http://acm.hdu.edu.cn/showproblem.php?pid=6144 解法:一个简单的模拟 #include <bits/stdc++.h> using names ...
- 2017"百度之星"程序设计大赛 - 复赛
Arithmetic of Bomb Accepts: 1050 Submissions: 1762 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 【2017百度之星程序设计大赛 - 复赛】Valley Numer
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6148 [题意] 在这里写题意 [题解] 先把1..N里面的山峰数字个数算出来->x 然后用N减去这 ...
- 2017"百度之星"程序设计大赛 - 初赛(A) [ hdu 6108 小C的倍数问题 ] [ hdu 6109 数据分割 ] [ hdu 6110 路径交 ] [ hdu 6112 今夕何夕 ] [ hdu 6113 度度熊的01世界 ]
这套题体验极差. PROBLEM 1001 - 小C的倍数问题 题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6108 (2017"百度之星 ...
随机推荐
- 【HTML5】input元素type属性值
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 【MySQL】查看支持的字符集show character set;
- Spring框架(四)AOP面向切面编程
一.前言 在以前的项目中,很少去关注spring aop的具体实现与理论,只是简单了解了一下什么是aop具体怎么用,看到了一篇博文写得还不错,就转载来学习一下,博文地址:http://www.cnbl ...
- VMware的一些总结
一.虚拟主机联网的三种方式: 1.仅主机(Host Only),虚拟主机只能与宿主机联网通信,无法访问外网和宿主机所在局域网的其它主机. 2.桥接(Bridge),在桥接模式下,虚拟主机就像是宿主机所 ...
- slowhttptest慢攻击工具介绍
slowhttptest介绍 Slowhttptest是依赖HTTP协议的慢速攻击DoS攻击工具,设计的基本原理是服务器在请求完全接收后才会进行处理,如果客户端的发送速度缓慢或者发送不完整,服务端为其 ...
- lodash源码分析之Hash缓存
在那小小的梦的暖阁,我为你收藏起整个季节的烟雨. --洛夫<灵河> 本文为读 lodash 源码的第四篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash gitbo ...
- bzoj 3192: [JLOI2013]删除物品
Description 箱子再分配问题需要解决如下问题: (1)一共有N个物品,堆成M堆. (2)所有物品都是一样的,但是它们有不同的优先级. (3)你只能够移动某堆中位于顶端的物品. ( ...
- UWP 应用通知Notifications
之前说UWP 使用OneDrive云存储2.x api(二)[全网首发],微识别实现了上传下载的功能,那么为了给用户更上一层楼的体验,那就是在上传下载完成之后,弹出一通知Notifications. ...
- go 1.9 Beta 1
语言变化:增加了类型别名 To find out what has changed in Go 1.9, read the draft release notes: https://tip.golan ...
- [摘抄]VC6.0移植到VS2008(vs2005)后的错误总结(未全部验证)
============================================================================================= 201405 ...