当前位置:网站首页>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;
}
边栏推荐
- Unity项目优化案例一
- "Everyday Mathematics" serial 56: February 25
- Netease UI automation test exploration: airtest+poco
- [combinatorics] non descending path problem (number of non descending paths with constraints)
- [sword finger offer] 58 - I. flip the word order
- 【剑指 Offer 】57 - II. 和为s的连续正数序列
- Develop team OKR in the way of "crowdfunding"
- Unreal_ Datatable implements ID self increment and sets rowname
- 面试之 top k问题
- 【剑指 Offer 】64. 求1+2+…+n
猜你喜欢

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

MySQL converts comma separated attribute field data from column to row

First knowledge of database

为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”

IDEA-配置插件

Idea configuration plug-in

Unreal_ Datatable implements ID self increment and sets rowname

Visual SLAM algorithms: a survey from 2010 to 2016

Cocos Creator 2.x 自动打包(构建 + 编译)

What is the pledge pool and how to pledge?
随机推荐
First knowledge of database
为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
What is the pledge pool and how to pledge?
Acwing game 58
Is it safe to open an account with flush?
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
2022.02.14_ Daily question leetcode five hundred and forty
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
Explore Netease's large-scale automated testing solutions see here see here
斑马识别成狗,AI犯错的原因被斯坦福找到了
Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
【剑指 Offer 】57 - II. 和为s的连续正数序列
Extraction of the same pointcut
Basis of target detection (IOU)
ThreeJS 第二篇:顶点概念、几何体结构
Page dynamics [2]keyframes
Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
Is it safe to open a stock account by mobile registration? Does it need money to open an account
word 退格键删除不了选中文本,只能按delete