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

L1-046 整除光棍 [大数相除]

时间:2019-03-10 20:32:17      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:sizeof   clu   std   src   return   def   bre   include   stream   

写都写了,当大数相除模版吧

技术图片
#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

 

L1-046 整除光棍 [大数相除]

标签:sizeof   clu   std   src   return   def   bre   include   stream   

原文地址:https://www.cnblogs.com/FTA-Macro/p/10506677.html

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