当前位置:网站首页>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;
}
边栏推荐
- [combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe
- Caching mechanism of Hibernate / session level caching mechanism
- Is it safe to open a stock account by mobile registration? Does it need money to open an account
- Interpretation of several important concepts of satellite antenna
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- MySQL single table field duplicate data takes the latest SQL statement
- A survey of state of the art on visual slam
- Mysql 单表字段重复数据取最新一条sql语句
- EditText request focus - EditText request focus
- 2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
猜你喜欢
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
Explore Netease's large-scale automated testing solutions see here see here
Multithread 02 thread join
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
面试官:JVM如何分配和回收堆外内存
Initial test of scikit learn Library
Netease UI automation test exploration: airtest+poco
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
TCP擁塞控制詳解 | 3. 設計空間
斑馬識別成狗,AI犯錯的原因被斯坦福找到了
随机推荐
1287. Elements that appear more than 25% in an ordered array
Top k questions of interview
Unreal_DataTable 实现Id自增与设置RowName
面试之 top k问题
Golang anonymous function use
Interpretation of several important concepts of satellite antenna
LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
MySQL single table field duplicate data takes the latest SQL statement
IDEA-配置插件
Daily code 300 lines learning notes day 10
(补)双指针专题
Explore Cassandra's decentralized distributed architecture
The mixlab editing team is recruiting teammates~~
深入理解 SQL 中的 Grouping Sets 语句
Record windows10 installation tensorflow-gpu2.4.0
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
Pointcut expression
Hong Kong Polytechnic University | data efficient reinforcement learning and adaptive optimal perimeter control of network traffic dynamics
Basis of target detection (IOU)
Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation