92分求助!!!我是第7个测试点出问题了
查看原帖
92分求助!!!我是第7个测试点出问题了
340603
陈家小仙男楼主2020/10/15 21:51
#include<bits/stdc++.h>
using namespace std;
int main(){
	stack<int> s;
	long long k;
	string x;
	string Ksum = "1";
	cin >> k >> x;
	for(int i = 0 ; i < k ; i ++){
		Ksum += '0';
	}
//	cout << Ksum << " " << x << endl;
	int len1 = x.length();
	int len2 = Ksum.length();
//	cout << len1 << " " << len2 << endl;
	int tempNum1,tempNum2,temp3;
	int flag = 0;
	while(len1 > 0 || len2 > 0){
		if(len1 > 0){
			tempNum1 = x[len1 - 1] - '0'; 
			len1 --;
		}
		else{
			tempNum1 = 0;
		}
		if(len2 > 0){
			tempNum2 = Ksum[len2 - 1] - '0';
			len2 --;
		}
		else{
			tempNum2 = 0;
		}
//		cout << tempNum1 << " " << tempNum2 << endl;
		s.push((tempNum2 + tempNum1) % 10 + flag);
		if(flag == 1) flag = 0;
		if(tempNum2 + tempNum1 >= 10){
			flag = 1;
		}
	}
	while(!s.empty()){
		cout << s.top();
		s.pop();
	}
}
2020/10/15 21:51
加载中...