Volume 1. Big Number(uva)
2024-08-23 21:31:54
如用到bign类参见大整数加减乘除模板
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#define N 10050
using namespace std;
string s;
int ans[N];
int main()
{
int i, j;
while (cin>>s, s[] != '')
{
for (i = s.length() - , j = ; i >= ; i--, j++)
ans[j] += (s[i] - '');
}
for (i = ; i < N - ; i++)
{
ans[i + ] += ans[i] / ;
ans[i] %= ;
}
i = N - ;
while (!ans[i] && i > )
i--;
while (i >= )
cout<<ans[i--];
cout<<endl;
return ;
}
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#define N 550
using namespace std;
int ans[N];
string s1, s2; int main()
{
int i, j, ls1, ls2, len;//tmp表示进位
while (cin>>s1>>s2)
{
ls1 = s1.length() - ;
ls2 = s2.length() - ;
len = ls1 + ls2;
memset(ans, , sizeof(ans));
for (i = ls1; i >= ; i--)
for (j = ls2; j >= ; j--)
{
ans[len - (i + j)] += (s1[i] - '') * (s2[j] - '');
}
len++;
for (i = ; i < len; i++)
{
ans[i + ] += ans[i] / ;
ans[i] = ans[i] % ;
}
while (!ans[len] && len > )//去除前导0
len--;
for (; len >= ; len--)
cout<<ans[len];
cout<<endl;
}
return ;
}
int main()
{
//ifstream cin("test.in");
bign a, b, c;
char ch;
bign d = INT_MAX;
string sa, sb;
while (cin>>sa>>ch>>sb)
{ cout<<sa<<' '<<ch<<' '<<sb<<endl;
a = sa;
b = sb;
if (d < a)
cout<<"first number too big"<<endl;
if (d < b)
cout<<"second number too big"<<endl;
if (ch == '+')
c = a + b;
else
c = a * b;
cout<<c<<endl;
if (d < c)
cout<<"result too big"<<endl;
}
return ;
}
int main()
{
string sa, sb;
bign a, b;
int p, n, i;
while (cin>>sa>>n)
{
p = ;
while (sa[p] != '.')
p++;
sa.erase(sa.begin() + p);
a = sa;
b = a ^ n;
sb = b.to_str();
p = ( - p) * n;
for (i = b.length(); i < p; i++)
sb += '';
sb.insert(sb.begin() + p, '.');
p = ;
while (sb[p] == '')
p++;
for (i = sb.length() - ; i >= p; i--)
cout<<sb[i];
cout<<endl;
}
return ;
}
10494 - If We Were a Child Again
int main()
{
//string sa, sb;
bign a, b, c;
char ch;
while (cin>>a>>ch>>b)
{
if (ch == '/')
c = a / b;
else
c = a % b;
cout<<c<<endl;
}
return ;
}
最新文章
- SAP 使用较频繁的日期时间处理函数总结
- Android studio git 本地仓库和远程仓库节点对比
- The main difference between Java &; C++(转载)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(9)
- WPF学习02:Routed Events
- ASP.Net用jQuery ajax实现页面局部刷新
- hdu3714 三分
- JavaScript高级程序设计(读书笔记)(一)
- ionic cordova platform add android Cordova failed to install plugin Error: ENOENT: no such file or directory AndroidManifest.xml
- 小P的字符串
- java常用技术名词解析
- 【原创】利用Office宏实现powershell payload远控
- jboss 异常处理
- 深入浅出 JMS(三) - ActiveMQ 消息传输
- 关于ARM的B,BL跳转指令
- 每日英语:Genetic Manipulation Extends Life of Mice 20%
- ExtJS错误解决 Cannot read property &#39;on&#39; of undefined
- css 盒子垂直居中
- 从U盘安装linux(前人踩坑后人乘凉)
- 解决:fontawesome-webfont.woff2?v=4.6.3 404 (Not Found)