1023. Have Fun with Numbers (20)

1.20位的数字,超过了unsigned long long的取值

2.采用string进行存储和检测

3.用哈希进行相同位检测

//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
//#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
using namespace std;
/*
3
0011111
The Testing Book
Yue Chen
test code debug sort keywords

2011
3333333
Another Testing Book
Yue Chen
test code sort keywords
ZUCS Print2
2012
2222222
The Testing Book
CYLL
keywords debug book
ZUCS Print2
2011
6
1: The Testing Book
2: Yue Chen
3: keywords
4:
5: 2011
3: blablabla

*/
int str2int(string s)
{
	int a = 0;
	for (int i = 0; i < s.size(); i++)
	{
		a = s[i] - '0' + a * 10;
	}
	return a;
}
int main(void)
{
	string s;
	cin >> s;
	string t = "";
	int carry = 0;
	bool ans = true;
	for (int i = s.size() - 1; i >= 0; i--)
	{
		int digit = (s[i] - '0') * 2 + carry;
		carry = digit / 10;
		char c = digit % 10 + '0';
		t = c + t;
	}
	if (carry != 0)
	{
		ans = false;
		char c = carry + '0';
		t = c + t;
	}
	if (ans)
	{
		int digit[10] = { 0 };
		for (int i = 0; i < s.size(); i++)
		{
			digit[s[i] - '0']++;
			digit[t[i] - '0']--;
		}
		for (int i = 0; i < 10; i++)
		{
			if (digit[i] != 0) ans = false;
		}
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	cout << t << endl;
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值