码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-2.4-fracdec-pass

时间:2014-09-09 12:17:38      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

呵呵,这个模拟题:

/*
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!

 

usaco-2.4-fracdec-pass

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/dpblue/p/3962062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!