PAT1017. 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

Idea: Be sure to pay attention to the connection between input variables
1#include <iostream>2 using namespacestd;3#include <string.h>4#include <stdio.h>5 intMainintargcChar*argv[])6 {7     Charnumber[1010];8     Charresul[1010]; 9     CharChushu;TenCin>>number>>Chushu; One     BOOLflag=true;//number of first digits A     intj=0; -     intReminder=0; -     intb=chushu- -; the      for(intI=0; number[i]!=' /'; i++) -     { -         inta=number[i]- -; -a=reminder*Ten+A; +         intc=a/B; -         intd=a%B; +     //cout<<c<<endl<<d<<endl; A         if(flag) at         { -flag=false; -            if(c>0) -resul[j++]=c+ -; -            Else if(c==0&&number[1]==' /') -resul[j++]=c+ -; inReminder=D; -             Continue;  to         } +         Else -         { theresul[j++]=c+ -; *Reminder=D; $             Panax Notoginseng         }        -      }  theresul[j]=' /';  +printf"%s%d\n", Resul,reminder);  A     return 0; the}
View Code



PAT1017. 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.