当前位置:网站首页>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;
}
边栏推荐
- [sword finger offer] 58 - I. flip the word order
- Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
- What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
- QT serial port UI design and solution to display Chinese garbled code
- Svn usage specification
- [statement] about searching sogk1997 and finding many web crawler results
- SVN使用规范
- NSQ源码安装运行过程
- Golang decorator mode and its use in NSQ
- 【剑指 Offer】58 - II. 左旋转字符串
猜你喜欢
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
(Supplement) double pointer topic
Multithread 02 thread join
Unreal_ Datatable implements ID self increment and sets rowname
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
Visual SLAM algorithms: a survey from 2010 to 2016
One article takes you to understand machine learning
A survey of state of the art on visual slam
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
随机推荐
JSON 与 BSON 区别
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
How to set up SVN server on this machine
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
2022爱分析· 国央企数字化厂商全景报告
IDEA-配置插件
TCP拥塞控制详解 | 3. 设计空间
【剑指 Offer 】64. 求1+2+…+n
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
Unreal_ Datatable implements ID self increment and sets rowname
[combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
探索Cassandra的去中心化分布式架构
Initial test of scikit learn Library
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
nifi从入门到实战(保姆级教程)——flow
How to initialize views when loading through storyboards- How is view initialized when loaded via a storyboard?
One article takes you to understand machine learning