1. 程式人生 > >1023 Have Fun with Numbers (20 分)(模擬加法)

1023 Have Fun with Numbers (20 分)(模擬加法)

水題一遍過,英語真的是差,double半天沒理解好,讀題讀半天

#include <cstdio>
#include <iostream>
#include <set>
#include <vector> 
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

char arr[50];

int i, j, jin, k, ans;
int bi1[50];
int bi2[50];

int main()
{
	cin >> arr;
	
	int l = strlen(arr);
	 
	for (i = 0; i<l; i++){
		bi1[arr[i]-'0']++;
	}
	
	for (j = l-1; j>=0; j--){
		k = (arr[j]-'0')*2;
		k += jin;
		bi2[k%10]++;
		arr[j] = k%10 + '0';
		jin = k/10;
	}
	
	if (jin) bi2[jin]++;
	
	for (i = 0; i<=9; i++)
		if (bi1[i] != bi2[i]){
			ans = 1;
			break;
		}	
	
	if (ans) cout << "No" << endl; else cout << "Yes" << endl;
	if (jin) cout << jin;
	cout << arr;
	
	return 0;
}