Codeforces Round #450 (Div. 2) + Liu Rugia Purple book 3-8 (c-language integer analog division)

Source: Internet
Author: User

Basic Template:

#include <iostream>
#include <cstdio>
using namespace std;

int main ()
{
    int a,b;
    int tem;
    while (~SCANF ("%d%d", &a,&b)) {for
        (int i=0;i<15;i++) {
            tem=a/b;
            A-=b*tem;
            a*=10;
            printf ("%d", tem);
            if (!i)
                printf (".");
        }
        printf ("\ n");
    }


Topic Link: Http://codeforces.com/contest/900/problem/B


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL Long
using namespace std;


int main ()
{
    int a,b,c;
    int Tem,cnt,flag;
    while (~SCANF ("%d%d%d", &a,&b,&c)) {
        cnt=flag=0;
        a*=10;
        for (int i=0;i<1000005;i++) {
            if (a==0) {if (
                c==0) {
                    flag=1;
                    cnt++;
                }
                break;
            tem=a/b;
            A-=b*tem;
            cnt++;
            a*=10;
            printf ("%d", tem);
            if (tem==c) {
                flag=1;
                break;
            }
        }
        if (flag)
            printf ("%d\n", CNT);
        else
            printf (" -1\n");
    }

Topic Link: VJ on UVa 202 self-opening

The code is as follows:

Even if it is decimal, it may not start with the first decimal number, so there will be errors in parentheses and the length of the Loop section, WA several times #include <iostream> #include <cstdio> #include <
Cstring> using namespace std; 
    int rm[1010];//The final result array int vis[1000010];//tag appears, storing the first occurrence of the position K int rec[1000010];//When k occurs, the value of divisor A is int main () {int a,b;
        while (~SCANF ("%d%d", &a,&b)) {memset (vis,0,sizeof (VIS));
        memset (Rec,0,sizeof (rec));
        printf ("%d/%d =%d", a,b,a/b);
        A=a%b;
        int k=1;
            while (!VIS[A]&AMP;&AMP;A)//if visited, the description is decimal, otherwise there is no cyclic solution {vis[a]=k;
            Rec[k]=a;
            a=a*10;
            rm[k++]=a/b;
        A=a%b;
        printf (".");
                for (int i=1;i<k&&i<=50;++i) {if (A&&a==rec[i])///When you start looping from this number, add parentheses, just expand the loop part
            printf ("(");
        printf ("%d", rm[i]);
        } if (!a) printf ("(0");
        if (k>50) printf ("...");
        printf (") \ n"); printf ("%d = numberof digits in repeating cycle\n ", a?
(K-vis[a]): 1);//k minus the cycle start position} return 0;
 }



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.