2017 "Baidu Star" program design contest-rematch 1001&&hdu 6144 arithmetic of Bomb "Java Big simulation"

Source: Internet
Author: User

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


Problem description is well known for the degree that bears like numbers very much.

It recently in the study of primary arithmetic, the first time to find the world there are two-digit, three-digit number ... Even the number of n digits!

But this time the arithmetic question is not simple, because contains the expression Bomb the # number, the degree degree bears call arithmetic of Bomb.



The Bomb in Bomb number, which is the #, expands some numbers, which leads to the final unfolding of the numbers beyond what the bear can understand. For example, "(1) # (3)" means "1" appears 3 times, will be expanded to "111",

Similarly, "(12) # (2) 4 (2) # (3)" will be expanded to "12124222".

For ease of understanding, the BNF representation of bomb number is given below.

```
<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 '
```

Expand all the # numbers in bomb number, as the numbers can be long and result in 1 000 000 007 modulo.

Input first behavior T, which represents the number of input data groups.

Each group of data contains one bomb Expression.


-1≤t≤100

-1≤length (Bomb number) ≤1000

Output results for each set of data export expressions, resulting in 1 000 000 007 modulo.

Sample Input
41 (1) # (3) (12) # (2) 4 (2) # (3) (12) # (5)

Sample Output
111112124222212121205

Source 201,700 Star Program Design contest-Rematch topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=6144 Analysis: thinking: Simulation; According to BNF, the number of repetitions is less than 10, The game is to use Notepad to smash Java code, a sad; The following is the AC code:
1 ImportJava.math.BigInteger;2 Importjava.util.Arrays;3 ImportJava.util.Scanner;4 5 ImportJavax.print.attribute.Size2DSyntax;6 7  Public classMain {8 9     /**Ten      * @paramargs One      */ A      Public Static voidMain (string[] args) -     { -Scanner in=NewScanner (system.in); the         intmod=1000000007; -          while(In.hasnextint ()) -         { -             intt=in.nextint (); +              for(inta=1;a<=t;a++) -             { +String s=In.next (); A                 LongAns=0; at                  for(intI=0;i<s.length (); i++) -                 { -                     if(S.charat (i) = = ' (') -                     { -                         intPos; -                          for(intJ=i;; J + +) in                         { -                             if(S.charat (j) = = ') ') to                             { +pos=J; -                                  Break; the                             } *                         } $                         intNum= (S.charat (pos+3)-' 0 ');Panax Notoginseng                          for(intk=0;k<num;k++) -                         { the                              for(intl=i+1;l<pos;l++) +                             { AAns= (Ans*10+s.charat (L)-' 0 ')%MoD; the                             } +                         } -I=pos+4; $                     } $                     Else -Ans= (Ans*10+s.charat (i)-' 0 ')%MoD; -                 } the System.out.println (ans); -             }Wuyi              the         } -     } Wu  -}

2017 "Baidu Star" program design contest-rematch 1001&&hdu 6144 arithmetic of Bomb "Java Big simulation"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.