#include <stdio.h>
#include <map>
using namespace std;

int main()
{
    int a, b, c, q, r, places;
    map<int, int> rmap;
    pair<map<int, int>::iterator, bool> pr;
    int qarr[50];
    while (scanf("%d %d", &a, &b) == 2)
    {
        rmap.clear();
        places = 0;
        r = a % b;

for (;;)    
        {
            c = r * 10;
            pr = rmap.insert(make_pair(c, places));
            if (!pr.second)
                break;
            q = c / b;
            r = c % b;
            if (places < 50)
                qarr[places] = q;
            ++places;
        }
        
        printf("%d/%d = %d.", a, b, a/b);
        r = places > 50 ? 50 : places;
        for (c = 0; c < r; ++c)
        {
            if (c == (pr.first)->second)
                putchar('(');
            printf("%d", qarr[c]);    
        }
        if (places > 50)
            printf("...");
        printf(")\n   %d = number of digits in repeating cycle\n\n", places - (pr.first)->second);
    }

return 0;
}

UVa202 Repeating Decimals的更多相关文章

  1. UVa 202 Repeating Decimals(抽屉原理)

    Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...

  2. Repeating Decimals UVA - 202---求循环部分

    原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...

  3. UVa 202 - Repeating Decimals

    给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...

  4. Repeating Decimals UVA - 202

    The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...

  5. uva 202(Repeating Decimals UVA - 202)

    题目大意 计算循环小数的位数,并且按照格式输出 怎么做 一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数.然后用第三个数组记录每一个被除数出现的位置好去 ...

  6. UVa 202 Repeating Decimals【模拟】

    题意:输入整数a和b,输出a/b的循环小数以及循环节的长度 学习的这一篇 http://blog.csdn.net/mobius_strip/article/details/39870555 因为n% ...

  7. 【习题 3-8 UVA - 202】Repeating Decimals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 余数出现循环节. 就代表出现了循环小数. [代码] #include <bits/stdc++.h> using nam ...

  8. UVa 202 Repeating Decimals 题解

    The decimal expansion of the fraction 1/33 is 0.03, where the 03 is used to indicate that the cycle ...

  9. [刷题]算法竞赛入门经典 3-7/UVa1368 3-8/UVa202 3-9/UVa10340

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa13 ...

随机推荐

  1. 扩展C++ string类

    在实际开发过程中,C++string类使用起来有很多不方便的地方,笔者根据根据这些不足简单的扩展了这个类,如增加与数字之间的相互转化和格式化字符串.不足的地方望指正.读者也可以根据自己需求继续扩展. ...

  2. poj2196---Specialized Four-Digit Numbers

    #include <stdio.h> #include <stdlib.h> int main() { int i,sum,sumOfH,sumOfd,tmp1,tmp2,tm ...

  3. linux内核参数调优,缓冲区调整,tcp/udp连接管理,保持,释放优化,gossary,terms

    changing a readonly file (linu single user mode)

  4. asp.net 前台js和后台得到FormView中的控件,以TextBox为例

    一.前台js获取FormView中的控件 js得到前端控件的ID,比如TextBox(这里设置其ID为TextBox1),大家都知道,是document.getElementById("&l ...

  5. 如何在MFC中操作资源句柄

    如何获取动态库中对话框相关资源,避免因资源问题报错? AfxGetResourceHandle用于获取当前资源模块句柄AfxSetResourceHandle则用于设置程序目前要使用的资源模块句柄. ...

  6. sql server 2005 表master..spt_values

    IF OBJECT_ID('tempdb..#t') IS NOT NULL DROP TABLE #tGOcreate table #t(id int identity,Dt varchar(10) ...

  7. iOS keyChain(钥匙串)的简单使用

    通常在开发中我们需要长久的保存某些值比如用户的账号密码等,对于隐私度很高的数据来说保证数据的安全性是尤为重要的.ios中的keyChain是一种很好的选择. 首先去开发者网站(https://deve ...

  8. 拔一拔 ExtJS 3.4 里你遇到的没遇到的 BUG(1)

    本文从今天开始,我要做的就是不断的更新,不断的披露ExtJS 3.4的BUG并修复它.需要注意的是版本为3.4而不是4.0,因为4.0改动和变化比较大,所以不要对号入座. 嘿嘿,本人不怎么写东西,不过 ...

  9. SnappyDB—Android上的NoSQL数据库简介

    参考:http://www.open-open.com/lib/view/open1420816891937.html 参考:http://android-arsenal.com/details/1/ ...

  10. CI(-)框架结构

    一 CI 是什么 CodeIgniter is an Application Development Framework - a toolkit - for people who build web ...