题目
题目链接
思路
题目的大意是给你一个最长不超过20位的十进制整数,问这个数乘2后每个字符出现的次数是否一样;
因为longlong int最多接受19位,故必须得自己用数组存了;
首先,对于测试数据,从末尾开始遍历,遍历的同时要干这些事情:1.将这个字符出现的次数统计出来;2.这个字符乘2加上上一次的进位就是结果的对应位置数字的大小;
感想
又双缀缀来做pat了,自己加油啊,奥利给!!!
单词
property:性质,性能,,财产
permutation:排列,置换
original:原始
代码
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
string s;
cin >> s;
int temp = 0;
vector<int> cnt1(10, 0), cnt2(10, 0), s2;
for(int i = s.size()-1; i >= 0; i--){
int a = s[i] - '0';
cnt1[a]++;
a = 2 * a + temp;
temp = a / 10;
cnt2[a % 10]++;
s2.push_back(a % 10);
}
if(temp != 0) s2.push_back(temp);
bool flag = true;
for(int i=0; i<10; i++){
if(cnt1[i] != cnt2[i]) {
flag = false;
break;
}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
for(int i=s2.size()-1; i>=0; i--) cout << s2[i];
return 0;
}