1.模拟*2运算
2.string的排序方法
3.string的逆序方法
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<set>
#include<map>
#include<sstream>
using namespace std;
int main() {
string s, ans="";
cin >> s;
int len = s.length(), flag = 0;
for(int i=len-1; i>=0; i--) {
int tmp = s[i]-'0';
tmp = tmp*2+flag;
if(tmp > 9) {
flag = 1;
tmp -= 10;
} else flag = 0;
ans += tmp+'0';
}
if(flag) {
ans += '1';
}
string tmp = ans;
sort(s.begin(), s.end());
sort(tmp.begin(), tmp.end());
if(s == tmp) {
cout << "Yes" << endl;
} else cout << "No" << endl;
string tans(ans.rbegin(), ans.rend() );
cout << tans << endl;
return 0;
}
本文介绍了一种模拟乘法运算的算法实现,并演示了如何使用C++进行字符串的排序和逆序操作。通过实例代码,展示了字符串处理技巧,包括逆序、排序以及比较两个字符串是否相等的过程。
432





