//#include<bits/stdc++.h>
#include<iostream>
#include<cctype>
using namespace std;
string s;
// 大整数 / 一位整数
string divide(string s, int x, int &yushu){
yushu = 0;
for(int i=0; i<s.size(); i++){
yushu = yushu*10 + (s[i]-'0');
s[i] = yushu / x + '0';
yushu = yushu % x;
}
int i = 0;
while(s[i]=='0'){
i++;
}
if(i>=s.size())
s = "??";
else
s = s.substr(i);
return s;
}
// 大整数 * 一位整数
string multiple(string s, int x){
int temp = 0;
for(int i=s.size()-1; i>=0; i--){
temp = (s[i]-'0') * x + temp;
s[i] = temp%10 + '0';
temp = temp/10;
}
// 最高位存在进位
if(temp!=0){
s = to_string(temp) + s;
}
return s;
}
// 大整数 + 一位整数
string add(string s, int x){
int temp = x;
if(x==0)
return s;
else{
for(int i=s.size()-1; i>=0; i--){
temp = (s[i]-'0') + temp;
s[i] = temp%10 + '0';
temp = temp/10;
}
}
// 最高位存在进位
if(temp!=0){
s = to_string(temp) + s;
}
return s;
}
int main()
{
cin>>s;
int yushu;
string ans = divide(s, 2, yushu);
cout<<ans<<endl;
ans = multiple(s, 2);
cout<<ans<<endl;
ans = add(s, 1);
cout<<ans<<endl;
return 0;
//样例:173
// 86 346 174
}
//例题:http://t.cn/AiCuoHKg
大整数除法、乘法、加法(C++实现)
最新推荐文章于 2024-01-29 12:03:52 发布