当前位置:网站首页>Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
2022-07-03 16:39:00 【Jun Yi_ noip】
【 Topic link 】
ybt 1175: Divide 13
OpenJudge NOI 1.13 27: Divide 13
【 Topic test site 】
1. High precision
Investigate : High precision except low precision High precision die low precision
Explanation of high-precision calculation
【 Solution code 】
solution 1: Use functions and arrays
#include <bits/stdc++.h>
using namespace std;
#define N 105
void toNum(char s[], int a[])
{
a[0] = strlen(s);
for(int i = 1; i <= a[0]; ++i)
a[i] = s[a[0] - i] - '0';
}
void showNum(int a[])
{
for(int i = a[0]; i >= 1; --i)
cout << a[i];
}
void setLen(int a[], int i)
{
while(a[i] == 0 && i > 1)
i--;
a[0] = i;
}
// High precision number divided by low precision number a For divisor b Divisor r For business , Return value is remainder
int Divide(int a[], int b, int r[])
{
int x = 0;//x: Is the remainder of the last division , And as the next minuend
for(int i = a[0]; i >= 1; --i)
{
r[i] = (x * 10 + a[i]) / b;
x = (x * 10 + a[i]) % b;
}
setLen(r, a[0]);
return x;
}
int main()
{
int a[N] = {
}, r[N] = {
}, m;
char s[N];
cin >> s;
toNum(s, a);
m = Divide(a, 13, r);
showNum(r);
cout << endl << m;
return 0;
}
solution 2: Overloaded operator in class
#include<bits/stdc++.h>
using namespace std;
#define N 105
struct HPN
{
int a[N];
HPN()
{
memset(a, 0, sizeof(a));
}
HPN(char s[])
{
memset(a, 0, sizeof(a));
a[0] = strlen(s);
for(int i = 1; i <= a[0]; ++i)
a[i] = s[a[0] - i] - '0';
}
int& operator [] (int i)
{
return a[i];
}
void setLen(int i)// Determine number of digits
{
while(a[i] == 0 && i > 1)
i--;
a[0] = i;
}
void show()
{
for(int i = a[0]; i >= 1; --i)
cout << a[i];
}
HPN operator / (int b) // High precision except low precision
{
int x = 0;
HPN r;
for(int i = a[0]; i >= 1; --i)
{
x = x * 10 + a[i];
r[i] = x / b;
x %= b;
}
r.setLen(a[0]);
return r;
}
int operator % (int b) // High precision die low precision
{
int x = 0;
for(int i = a[0]; i >= 1; --i)
x = (x * 10 + a[i]) % b;
return x;
}
};
int main()
{
char s[N];
cin >> s;
HPN a(s), r;
int m;
r = a / 13;// High precision except low precision
m = a % 13;// High precision die low precision
r.show();
cout << endl << m;
return 0;
}
边栏推荐
- Interpretation of several important concepts of satellite antenna
- 2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
- Golang anonymous function use
- 2022爱分析· 国央企数字化厂商全景报告
- Record windows10 installation tensorflow-gpu2.4.0
- Golang 匿名函数使用
- Construction practice camp - graduation summary of phase 6
- Interviewer: how does the JVM allocate and recycle off heap memory
- [combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
- MySQL converts comma separated attribute field data from column to row
猜你喜欢

Processing strategy of message queue message loss and repeated message sending

Deep understanding of grouping sets statements in SQL

Simulink oscilloscope data is imported into Matlab and drawn

【LeetCode】94. Middle order traversal of binary tree

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

Add color to the interface automation test framework and realize the enterprise wechat test report

斑馬識別成狗,AI犯錯的原因被斯坦福找到了

Daily code 300 lines learning notes day 10

跟我学企业级flutter项目:简化框架demo参考

TCP擁塞控制詳解 | 3. 設計空間
随机推荐
MySQL single table field duplicate data takes the latest SQL statement
The word backspace key cannot delete the selected text, so you can only press Delete
SVN使用规范
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
How programming apes grow rapidly
14 topics for performance interviews between superiors and subordinates (4)
利用MySQL中的乐观锁和悲观锁实现分布式锁
Is it safe to open a stock account by mobile registration? Does it need money to open an account
Mysql 将逗号隔开的属性字段数据由列转行
【剑指 Offer 】64. 求1+2+…+n
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
Golang anonymous function use
Visual SLAM algorithms: a survey from 2010 to 2016
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
【剑指 Offer 】57 - II. 和为s的连续正数序列
Explore Cassandra's decentralized distributed architecture
Unreal_ Datatable implements ID self increment and sets rowname
Cocos Creator 2.x 自动打包(构建 + 编译)
[Jianzhi offer] 64 Find 1+2+... +n
程序猿如何快速成长