首页 > 代码库 > usaco-2.4-fracdec-pass
usaco-2.4-fracdec-pass
呵呵,这个模拟题:
/*ID: qq104801LANG: 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 TrainingGrader Results 8 users onlineCHN/3 USA/5USER: cn tom [qq104801]TASK: fracdecLANG: C++Compiling...Compile: OKExecuting... 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 4885Keep up the good work!Thanks for your submission!
usaco-2.4-fracdec-pass
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。