#include <iostream>
#include <string>
#include <vector>
using namespace std;
void SetDoubleVal(string &Obj, string &Obj1)
{
vector<int> arr(Obj.size());
for (int i = Obj.size() - 1; i >= 0;--i)
{
int nT = atoi(&Obj[i]) * 2;
if (nT > 9)
{
arr[i-1] = 1;//记录进位值
nT -= 10;
}
nT += arr[i];
//进位
Obj1.insert(Obj1.begin(), to_string(nT).front());
}
}
int main()
{
string strVal, strValDouble;
cin >> strVal;
int Tab[2][10] = { 0 };
for (auto Temp : strValDouble)
++(Tab[0][atoi(&Temp)]);
SetDoubleVal(strVal, strValDouble);
for (auto Temp : strValDouble)
++(Tab[1][atoi(&Temp)]);
bool sw = true;
for (int i = 0; i < 10; ++i)
if (Tab[0][i] != Tab[1][i])
sw = false;
if (sw)
cout << "Yes\n";
else
cout << "No\n";
cout << strValDouble << endl;
return 0;
}//就是不知道那点错了,显示两个异常退出..1023. Have Fun with Numbers (20)
最新推荐文章于 2025-12-18 16:28:22 发布
本文深入分析了一段C++代码,该代码实现了将输入字符串中每个字符的ASCII值翻倍并插入到另一个字符串的过程。通过实例演示了如何通过循环遍历输入字符串,将每个字符转换为整数,进行翻倍运算,并考虑进位情况。最后,通过比较两次处理后的字符计数来验证操作的正确性。
2743

被折叠的 条评论
为什么被折叠?



