1017 A除以B (20 分)

博客介绍了一道题的常规做法是模拟计算除法过程,被除数不超两位,一次遍历即可。提到Python中大整数不会超范围,降低了题目的难度,还给出了C++和Python3代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

  1. 常规做法应该就是模拟计算除法的过程,被除数应该不超过两位。
  2. 进行一次遍历即可。
  3. python中大整数并不会超范围,瞬间把这道题的难度拉没了。

c++代码

#include <iostream>
#include<string>
#include<vector> 
#include<queue>
#include <algorithm>
using namespace std;


int main() {
	string s;
	int a = 0;
	int b;
	queue<int>q;
	vector<int>res;
	cin >> s >> b;
	for (int i = 0; i < s.size(); i++) {
		q.push(s[i] - '0');
	}
	while (!q.empty()) {
		a = a * 10 + q.front();
		q.pop();

		res.push_back(a / b);
		a = a % b;
	}
	int i = 0;
	if (res.size() > 1 && res[0] == 0) //防止商为0的情况
		i++;
	for (; i < res.size(); i++) {
		cout << res[i];
	}
	cout << " " << a << endl;
	return 0;
}
复制代码

python3代码

def main():
    s = list(map(int,input().split()))
    print('{} {}'.format(s[0]//s[1],s[0]%s[1]))
main()
复制代码

转载于:https://juejin.im/post/5ce7f3145188252db119bc69

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值