• usaco-2.4-fracdec-pass


    呵呵,这个模拟题:

    /*
    ID: qq104801
    LANG: C++
    TASK: fracdec
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <list>
    #include <set>
    #include <queue>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    int n,d;
    int vv[111111];
    vector<int> ans;
    string ss;
    
    void ff(int i)
    {
        if(i>=10)ff(i/10);
        ss+='0'+i%10;
    }
    
    void test()
    {    
        freopen("fracdec.in","r",stdin);
        freopen("fracdec.out","w",stdout);
        cin>>n>>d;
        ff(n/d);
        n%=d;
        bool b=1;
        while(!vv[n])
        {
            vv[n]=ans.size()+1;
            ans.push_back(n*10/d);
            n=(n*10)%d;
            if(n==0){
                vv[n]=ans.size();
                b=0;
                break;
            }
        }
        ss+='.';
        for(int i=0;i<vv[n]-1;++i)
            ss+=ans[i]+'0';
        if(b)ss+='(';
        for(int i=vv[n]-1;i<ans.size();++i)
            ss+=ans[i]+'0';
        if(b) ss+=')';
        for(int i=0,j=0;i<ss.size();++i)
        {
            if(j==76)
            {
                puts("");
                putchar(ss[i]);
                j=1;
                continue;
            }
            else
            {
                putchar(ss[i]);
                j++;
            }
        }
        if(ss.size()%76==0);
        else puts("");  
    
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    8 users online
    CHN/3 USA/5
    
    USER: cn tom [qq104801]
    TASK: fracdec
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.005 secs, 3940 KB]
       Test 2: TEST OK [0.003 secs, 3940 KB]
       Test 3: TEST OK [0.005 secs, 3940 KB]
       Test 4: TEST OK [0.008 secs, 3940 KB]
       Test 5: TEST OK [0.016 secs, 3940 KB]
       Test 6: TEST OK [0.003 secs, 3940 KB]
       Test 7: TEST OK [0.011 secs, 3940 KB]
       Test 8: TEST OK [0.019 secs, 3940 KB]
       Test 9: TEST OK [0.008 secs, 3940 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('fracdec') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    22 5
    ------- test 2 ----
    1 7
    ------- test 3 ----
    100000 59
    ------- test 4 ----
    1 100000
    ------- test 5 ----
    3 3
    ------- test 6 ----
    59 330
    ------- test 7 ----
    100000 9817
    ------- test 8 ----
    1 99991
    ------- test 9 ----
    982 4885
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    iOS 开发--NSMutableArray使用枚举方法
    IOS开发中的几种设计模式
    iOS开发--提交github代码
    iOS开发--CornerStone上传静态库(.a文件)
    iOS开发swift--函数
    iOS开发--自动布局
    iOS开发--邮箱,电话号码,身份证正则表达式验证
    Redis学习笔记~实现消息队列比MSMQ更方便
    WebApi系列~基于RESTful标准的Web Api
    推荐一个简单、轻量、功能非常强大的C#/ASP.NET定时任务执行管理器组件–FluentScheduler定时器
  • 原文地址:https://www.cnblogs.com/dpblue/p/3962062.html
Copyright © 2020-2023  润新知