to short on line 1 ????
查看原帖
to short on line 1 ????
505484
冬笙夏洛_楼主2021/4/25 14:35

80分,最后一个WA```cpp

#include<bits/stdc++.h>

using namespace std;
//计算数的位数
int cal(int n) {
	int count = 0;
	while (n) {
		n /= 10;
		count++;
	}
	return count;
}
string discuss1(string a, int b) {
	//a的位数
	int la = a.size();
	//b的位数
	int lb = cal(b);

	if (la < lb)
		return string("0");
	//a,b位数相同
	else if (la == lb)
	{
		//t1 是下标的意思
		int t1 = 0;
		while (1) {
			//int(b / pow(10, lb - t1 - 1))%10 是取出b中的第 t1个数 和 字符串a中第t1 个数对比
			if (a[t1] - '0' < int(b / pow(10, lb - t1 - 1))%10)
				return string("0");
			else if (a[t1] - '0' > int(b / pow(10, lb - t1 - 1))%10)
				break;
			else
			{
				t1++;
			}
		}
	}

	int temp;
	int i = 0;
	temp = a[i] - '0';
	while (temp < b) {
		temp = temp * 10 + a[++i] - '0';
	}
	
	int  num[200005] = {};
	int k;
	for (k=0;i < la;i++) {
		num[k++] = temp / b;
		temp = (temp%b) * 10 + a[i + 1]-'0';

	}
	string ans;
	for (int i = 0;i < k;i++)
		ans += num[i] + '0';

	return ans;

}
int main() {
	string a;
	int b;
	cin >> a >> b;
	cout << discuss1(a, b) << endl;
	return 0;
}
2021/4/25 14:35
加载中...