当前位置:网站首页>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;
}
边栏推荐
- Hong Kong Polytechnic University | data efficient reinforcement learning and adaptive optimal perimeter control of network traffic dynamics
- (补)双指针专题
- Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- Visual SLAM algorithms: a survey from 2010 to 2016
- Acwing game 58
- 【LeetCode】94. Middle order traversal of binary tree
- 2022.02.14_ Daily question leetcode five hundred and forty
- Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation
- 【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
- Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
猜你喜欢

NSQ源码安装运行过程

探索Cassandra的去中心化分布式架构

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

2022.02.14_ Daily question leetcode five hundred and forty

Initial test of scikit learn Library

【LeetCode】94. Middle order traversal of binary tree

Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford

Data driving of appium framework for mobile terminal automated testing

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)

arduino-esp32:LVGL项目(一)整体框架
随机推荐
【剑指 Offer 】57 - II. 和为s的连续正数序列
What is the maximum number of concurrent TCP connections for a server? 65535?
Initial test of scikit learn Library
Golang decorator mode and its use in NSQ
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
Chinese translation of Tagore's floating birds (1~10)
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
Arduino esp32: overall framework of lvgl project (I)
【剑指 Offer】58 - I. 翻转单词顺序
Golang anonymous function use
PHP二级域名session共享方案
JSON 与 BSON 区别
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Deep understanding of grouping sets statements in SQL
word 退格键删除不了选中文本,只能按delete
The mixlab editing team is recruiting teammates~~
Acwing game 58
一台服务器最大并发 tcp 连接数多少?65535?