PAT 1017. A divided by B (20)

Source: Internet
Author: User

The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.

Input format:

The input is given a and B in 1 rows, and the middle is separated by 1 spaces.

Output format:

In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.

Input Sample:

123456789050987654321 7

Sample output:

17636684150141093474 3
This problem to find long time fault, in this machine debugging multiple answers are correct, but after submission is not, finally found that temp did not assign the initial value of 0. Pay more attention to it later.
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <stdlib.h>5 intMain () {6     Chara[ -];7scanf"%s", a);8     intb;9scanf"%d",&b);Ten     intn =strlen (a); One     inttemp=0; A     intFlag =0; -      for(intI=0; i<n;i++){ -temp = (a[i]-'0') +temp*Ten; the         if(temp>=b) { -printf"%d", temp/b); -Flag =1; -         } +         Else if(flag) { -printf"0"); +         } Atemp = temp%b; at     } -     if(flag==0) -printf"0"); -printf"%d", temp); -}

PAT 1017. A divided by B (20)

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.