BESTCODER#33 1001 High-precision simulation

Source: Internet
Author: User

BESTCODER#33 1001 High Precision analog ZHX ' s submissions


Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0


Problem Descriptionas One of the most powerful brushes, ZHX submits a lot of code in many OJ and most of them got AC.
One day, Zhx wants to count about many submissions he made on $n $ OJS. He knows that on the $i ^{th}$ OJ, he made $a _i$ submissions. And what are should do are to add them up.
The problem more complex, ZHX gives you $n $ $B-base$ numbers and you should also return a $B-base$ number to him.
What's more, zhx are so naive the he doesn ' t carry a number while adding. That means, he answer to $ $ + 6$ in $10-base$ is $1$. And he also asked you to calculate on his. Inputmultiply test Cases (less than $1000$). Seek $EOF $ as the end of the file.
For each test, there is integers $n $ and $B $ separated by a space. ($ \leq N \leq 100$, $ \leq B \leq 36$)
Then come n lines. All line there are a $B-base$ number (may contain leading zeros). The digits is from $0$ to $9$ and then from $a $ to $z $ (lowercase). The length of a number would not be execeed 200. Outputfor each test case, output A, indicating the answer in $B-base$ (no leading zero). Sample Input2 3221 42333 16ABBCCD sample Output123314 test instructions: high-precision addition to n-B binary numbers for non-rounding, go to leading 0 output results at first Test instructions did not see clearly by case misled thought to turn into decimal output: Then choose to use String to do ... The code is tedious but not ac ... Originally a little calm think can be a short period of 1 a problem incredibly did not be able to AC, it seems that the limited time of the game training is not much, but also because the algorithm when the brush problem procrastination, do not think good thinking on blindly write code, do not carefully analyze the problem, it seems to increase time-limited training, to form a cool heart quality Learn the algorithm at the same time clear thinking
//bestcoder#33_1001#include <iostream>#include<stdio.h>#include<string.h>#include<ctype.h>using namespacestd;Const intmaxn= About;Const intInf= (1<< -);intn,b;intA[MAXN];CharSTR[MAXN];//The definition of an array takes time, so try to avoid the definition in the loop as many times as possible .intGetnum (Charch) {    if(ch<='9'&&ch>='0')returnch-'0'; returnch-'a'+Ten;}intMain () { while(SCANF ("%d%d", &n,&b)! =EOF) {memset (A,0,sizeof(a));  while(n--) {scanf ("%s", str); intlen=strlen (str);  for(intI=0; i<len;i++) {A[i]= (A[i]+getnum (str[len-1-i]))%B;//perform high-precision operations by test instructions simulation and turning into integers            }        }        intlen=MAXN;  while(a[len-1]==0&&len>1) len--;//Go leading 0         for(inti=len-1; i>=0; i--) {//Output            if(a[i]<=9) printf ("%c",(Char) (a[i]+'0')); Elseprintf"%c",(Char) (a[i]-Ten+'a')); } printf ("\ n"); }    return 0;}
bestcoder#33_1001

BESTCODER#33 1001 High-precision 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.