#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++静态分析工具 —— CppDepend

    Wrote by mutouyun. (http://darkc.at/cppdepend/) 去年6月份的时候,CppDepend的一位技术社区经理(technical community mana ...

  2. 一个基于MINA框架应用的最简单例子

    直接上代码.关于原理和主要的API以后在说.先能跑通了在说. 主要的包:mina-core-2.0.0.jar[到官网上下载完整项目包里面还有文档和依赖包],jcl-over-slf4j-1.5.11 ...

  3. 美国TJX公司 - MBA智库百科

    美国TJX公司 - MBA智库百科 TJX公司总部设在美国波士顿,在北美地区和许多欧洲国家开有连锁分店,仅在美国就有2500多家分店. TJX Companies, Inc. 是美国和全世界的服装和家 ...

  4. Go语言简单的TCP编程

    前期准备 需要import "net"包 IP类型,其中一个重要的方法是IP.ParseIP(ipaddr string)来判断是否是合法的IP地址 TCP Client func ...

  5. 深入理解Linux网络技术内幕——中断与网络驱动程序

    接收到帧时通知驱动程序     在网络环境中.设备(网卡)接收到一个数据帧时,须要通知驱动程序进行处理. 有一下几种通知机制: 轮询:     内核不断检查设备是否有话要说.(比較耗资源,但在一些情况 ...

  6. 前端新人学习笔记-------html/css/js基础知识点(二)

    4月7日学到的知识点:     一:<img src="1.png" alt="美女"/> alt是给图片添加介绍,当图片没加载出来时,会直接显示a ...

  7. 不定高度实现垂直居中(兼容低版本ie)

    css实现垂直居中的方法比较多,但是每种方法的缺陷也很明显,我尝试对其中一种方法进行了改良 先看原方法: <div class="parent"> <div cl ...

  8. 征服 Redis + Jedis + Spring —— 配置&常规操作

    Spring提供了对于Redis的专门支持:spring-data-redis.此外,类似的还有: 我想大部分人对spring-data-hadoop.spring-data-mongodb.spri ...

  9. IOS开发——正则表达式验证手机号、密码

    App的实际应用中,用户登陆功能基本是每个App都有需求的一个功能.而当前我们很常规的做法,就是让用户把手机号作为自己的用户名,而在注册获取短信验证码的过程中,我们首先要完成的一个步骤,就是校验用户的 ...

  10. Do not go gentle into that good night

    Do not go gentle into that good night By:Dylan Thomas   Do not go gentle into that good night,Old ag ...