L1-046 整除光棍 [大数相除]
作者:互联网
写都写了,当大数相除模版吧
#include<iostream> #include<cstdio> #include<string.h> #include<string> #include<math.h> #include<map> #define maxn 10005 using namespace std; typedef long long ll; int n,p; string s; int ans[maxn]; bool judge(string ss) { int l=ss.length(); int sum=0; for(int i=0;i<l;i++) { sum=sum*10+s[i]-'0'; if(sum<n) { ans[p++]=0; } else { ans[p++]=sum/n; sum=sum%n; } } if(sum==0) return true; else return false; } int main() { scanf("%d",&n); for(int i=0;i<1000;i++) { s=s+"1"; p=0; memset(ans,0,sizeof(ans)); if(judge(s)) { int flag=1; for(int i=0;i<p;i++) { if(ans[i]==0&&flag) continue; else { printf("%d",ans[i]); flag=0; } } printf(" %d\n",s.length()); break; } } return 0; }View Code
标签:string,int,long,maxn,相除,L1,046,include 来源: https://www.cnblogs.com/FTA-Macro/p/10506677.html