PAT乙题1017. A除以B (20)

2018/01/25 PAT 共 531 字,约 2 分钟
#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
#ifdef LOCAL
	freopen("d:\\datain.txt", "r", stdin);
	//freopen("d:\\dataout.txt", "w", stdout);
#endif LOCAL
	string s;
	int a;
	cin >> s >> a;
	int len = s.length();
	int t = (int)(s[0] - '0') / a;
	if (len == 1 || (t != 0 && len > 1)) {
		cout << t;
	}
	int temp = (s[0] - '0') % a;
	for (int i = 1; i < len; i++) {
		int t = (temp * 10 + s[i] - '0') / a;
		cout << t;
		temp = (temp * 10 + s[i] - '0') % a;
	}
	cout << " " << temp;
}

Search

    Table of Contents