1023. Have Fun with Numbers (20)
来源:互联网 发布:最新网络3d游戏排名 编辑:程序博客网 时间:2024/05/23 02:01
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;/*30011111The Testing BookYue Chentest code debug sort keywords20113333333Another Testing BookYue Chentest code sort keywordsZUCS Print220122222222The Testing BookCYLLkeywords debug bookZUCS Print2201161: The Testing Book2: Yue Chen3: keywords4:5: 20113: 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
- 1023. Have Fun with Numbers (20)
- 【PAT】1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT: 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- js面向对象初步学习
- 月薪3万的程序员都避开了哪些坑
- s开始学习SLAM
- python刚入门,还需多努力
- discuz 获取会员头像
- 1023. Have Fun with Numbers (20)
- PCB布线原则
- (SRC)基于稀疏表示的人脸识别
- Fragment:碎片的动态加载
- fread
- 提高cookie安全性的几种方法
- Samba服务器的安装与配置(Ubuntu14.04)
- PCB Layout 中的直角走线、差分走线和蛇形线
- javascrip学习之旅