加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 大数据 > 正文

大数/小数,大数%小数

发布时间:2021-01-20 18:00:58 所属栏目:大数据 来源:网络整理
导读:1.string / int #includeiostream#includecstdio#includecmath#includecstdlib#includecstring#includealgorithmusing namespace std;string div(string str,int x){ string ans=""; int len=str.size(); int y=0; for(int i=0;ilen;i++) { ans+=(char)((y

1.string / int

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

string div(string str,int x)
{
  string ans="";
  int len=str.size();
  int y=0;
  for(int i=0;i<len;i++)
  {
    ans+=(char)((y*10+(str[i]-'0'))/x+'0');
    y=(y*10+(str[i]-'0'))%x;
  }
  while(*(ans.begin())=='0'&&ans.size()>1)
    ans.erase(ans.begin());
  return ans;
}

int main()
{
  string a;
  int b;
  cin>>a>>b;
  cout<<div(a,b)<<endl;
}

2.string%int

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int mod(string str,int x)
{
//  string ans="";
  int len=str.size();
  int y=0;
  for(int i=0;i<len;i++)
  {
//    ans+=(char)((y*10+(str[i]-'0'))/x+'0');
    y=(y*10+(str[i]-'0'))%x;
  }
//  while(*(ans.begin())=='0'&&ans.size()>1)
//    ans.erase(ans.begin());
  return y;
}

int main()
{
  string a;
  int b;
  cin>>a>>b;
  cout<<mod(a,b)<<endl;
}

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读