当前位置:网站首页>Luogu questionnaire - high accuracy
Luogu questionnaire - high accuracy
2022-07-18 12:16:00 【Crayon gold QAQ】
# Rogue list - High precision
### Add

[ Portal ](https://www.luogu.com.cn/problem/P1601)
```cpp
#include <bits/stdc++.h>
using namespace std;
// https://www.luogu.com.cn/problem/P1601
char n1[10000], n2[10000];
int num1[10000], num2[10000];
int ans[10000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n1;
cin >> n2;
int len1 = strlen(n1);
int len2 = strlen(n2);
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= len1; i++)
{
num1[i] = n1[len1 - i] - '0';
// cout << num1[i];
}
// cout << endl;
for (int i = 1; i <= len2; i++)
{
num2[i] = n2[len2 - i] - '0';
// cout << num2[i];
}
// cout << endl;
int lenc = 1;
int mod1 = 0;
while (lenc <= len1 || lenc <= len2)
{
ans[lenc] = num1[lenc] + num2[lenc] + mod1;
mod1 = ans[lenc] / 10;
ans[lenc] %= 10;
lenc++;
}
ans[lenc] = mod1;
if (ans[lenc] == 0)
lenc--; // Prevent previous 0
for (int i = lenc; i > 0; i--)
{
cout << ans[i];
}
return 0;
}
```
### Subtraction

[ Portal ](https://www.luogu.com.cn/problem/P2142)
```cpp
#include <bits/stdc++.h>
using namespace std;
// https://www.luogu.com.cn/problem/P2142
char n1[1000000], n2[1000000];
char remp[1000000];
int num1[1000000], num2[1000000];
int ans[1000000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n1 >> n2;
if (strlen(n1) < strlen(n2) || (strlen(n1) == strlen(n2) && strcmp(n1, n2) < 0))
{
// When the subtracted is less than the subtracted , In exchange , And add “-”
strcpy(remp, n1);
strcpy(n1, n2);
strcpy(n2, remp);
cout << "-";
}
int len1 = strlen(n1);
int len2 = strlen(n2);
for (int i = 1; i <= len1; i++)
{
num1[i] = n1[len1 - i] - '0';
}
for (int i = 1; i <= len2; i++)
{
num2[i] = n2[len2 - i] - '0';
}
int lenc = 1;
while (lenc <= len1 || lenc <= len2)
{
if (num1[lenc] < num2[lenc])
{
num1[lenc] += 10;
num1[lenc + 1]--;
}
ans[lenc] = num1[lenc] - num2[lenc];
// cout << num1[lenc] << " " << num2[lenc] << " " << ans[lenc] << " " << lenc << endl;
lenc++;
}
while (ans[lenc] == 0 && lenc > 1) // lenc Greater than 1 Not greater than or equal to !
{
lenc--;
}
for (int i = lenc; i >= 1; i--)
{
cout << ans[i];
}
}
```
### Multiplication

[ Portal ](https://www.luogu.com.cn/problem/P1303)
```cpp
#include <bits/stdc++.h>
using namespace std;
char n1[1000000], n2[1000000];
int num1[1000000], num2[1000000], ans[1000000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n1;
cin >> n2;
int len1 = strlen(n1);
int len2 = strlen(n2);
for (int i = 1; i <= len1; i++)
{
num1[i] = n1[len1 - i] - '0';
}
for (int i = 1; i <= len2; i++)
{
num2[i] = n2[len2 - i] - '0';
}
for (int i = 1; i <= len1; i++)
{
int mod1 = 0; // Used to carry
for (int j = 1; j <= len2; j++)
{
ans[i + j - 1] += num1[i] * num2[j] + mod1;
mod1 = ans[i + j - 1] / 10;
ans[i + j - 1] %= 10;
}
ans[i + len2] = mod1;
}
int lenc = len1 + len2;
while (lenc > 1 && ans[lenc] == 0)
lenc--;
for (int i = lenc; i > 0; i--)
cout << ans[i];
return 0;
}
```
### division

[ Portal ](https://www.luogu.com.cn/problem/P1480)
```cpp
#include <bits/stdc++.h>
using namespace std;
char n1[1000000];
int num1[1000000], ans[1000000];
long long num2;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n1;
cin >> num2;
int len1 = strlen(n1);
for (int i = 1; i <= len1; i++)
{
num1[i] = n1[i - 1] - '0';
}
long long mod1 = 0;
for (int i = 1; i <= len1; i++)
{
ans[i] = (mod1 * 10 + num1[i]) / num2;
// cout<<ans[i]<<endl;
mod1 = (mod1 * 10 + num1[i]) % num2;
}
int lenc = 1;
while (lenc < len1 && ans[lenc] == 0)
lenc++;
for (int i = lenc; i <= len1; i++)
cout << ans[i];
return 0;
}
```
边栏推荐
- 自动推理的逻辑01
- 小程序容器技术在Hybrid 混合App开发中的价值
- 【微信小程序】基本橫向、纵向滚动Scroll-view(95/100)
- GDB or delve debug Go program, check variable display < optimized out > solution
- Interview question 04.06 Successor DFS plus auxiliary variable traversal
- Web 编程面试题(2022)
- 【鸡汤】天下事有难易乎
- Flink basic record supplement
- Redis data structure practice, see how microblogging, wechat, shopping cart, lottery applet is used?
- uniapp uni-popup change
猜你喜欢
随机推荐
AcWing 395. Redundant path problem solution (biconnected component of undirected graph)
You can't answer these 20 classic redis interview questions yet, and the interviewer doesn't even look at you
Summarize the differences between i++ and i++
【微信小程序】基本橫向、纵向滚动Scroll-view(95/100)
Flink basic record supplement
2022年7月16日CDGA/CDGP数据治理认证考试成绩出来啦!
HDOJ-2057(A + B Again)
Power BI----DAX讲解
Differences among screenwidth, clientwidth, offsetwidth, and scrollwidth
Openeuler knows: the solution of IP addr not finding IP
The value of applet container technology in hybrid hybrid app development
Solve the "cannot find module 'path' or its corresponding type declarations." in TS
Community summit pulsar summit old golden peak conference topic highlights exposure!
pinctrl子系统和gpio子系统
C# 使用JObject解析嵌套json
Statistics of Top100 domestic NFT Platform Alliance chain and public chain usage
AcWing 368. 银河 题解(强连通分量做差分约束问题)
Xunwei Godson development board domestic dual core 64 bit loognix system dual Gigabit Ethernet more interfaces
Résolution du format d'image
Web programming interview question (2022)









