我醉了,高精都能写错

P1480 A/B Problem

拒绝gets从我做起
by Fraction @ 2018-11-09 17:55:36


所以到底哪错了 ```cpp #include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool first; int main() { char a[5001]; int b,i=0,len,w=0; gets(a); scanf("%d",&b); len=strlen(a); while(i<len) { if(w>=b) { first=1; printf("%d",w/b); w=w%b; } else if(first) printf("0"); w=w*10+(a[i]-'0'); i++; } if(w>=b) { printf("%d",w/b); first=1; w=w%b; } else if(first&&w>0) printf("0"); if(!first) printf("0"); return 0; } ```
by resftlmuttmotw @ 2018-11-09 17:57:11


用gets会错吗
by resftlmuttmotw @ 2018-11-09 17:57:36


@[resftlmuttmotw](/space/show?uid=73992) 用gets在有些题目中会直接CE
by Eason_AC @ 2018-11-09 18:00:18


你是高精除以高精吗
by Eason_AC @ 2018-11-09 18:00:52


还是高精除以低精
by Eason_AC @ 2018-11-09 18:01:10


看一下我的吧 ```cpp #include <bits/stdc++.h> using namespace std; int main() { char a1[5001]; int a[5001],c[50001],lena,i,x=0,lenc,b; memset(a,0,sizeof(a)); memset(c,0,sizeof(c)); scanf("%s",a1); cin>>b; lena=strlen(a1); for(i=0; i<=lena-1; i++) a[i+1]=a1[i]-48; for(i=1; i<=lena; i++) { c[i]=(x*10+a[i])/b; x=(x*10+a[i])%b; } lenc=1; while(c[lenc]==0 && lenc<lena) lenc++; for(i=lenc; i<=lena; i++) cout<<c[i]; cout<<endl; return 0; } ```
by Eason_AC @ 2018-11-09 18:01:54


用字符数组输入输出很好的,可以直接用scanf("%s",...)输入(可以小于数组长度)
by Eason_AC @ 2018-11-09 18:02:53


@[Fraction](/space/show?uid=32107) +1,Gets有毒
by 「ゲームとOI」 @ 2018-11-09 18:07:20


这道题是高除底啊
by resftlmuttmotw @ 2018-11-09 18:13:26


| 下一页