解题思路:这道题用数组做会方便一点。如果不想用数组做,就需要像下面这么麻烦。
注意事项:建议还是学习用数组做
参考代码:
#include<iostream>
using namespace std;
int main()
{
int x, n;
cin >> x;
if (x < 100000)
{
int a = x / 10000;
int b = x / 1000 - 10 * a;
int c = x / 100 - 100 * a - 10 * b;
int d = x / 10 - 1000 * a - 100 * b - 10 * c;
int e = x - 10000 * a - 1000 * b - 100 * c - 10 * d;
if (a > 0)
{
cout << 5 << endl;
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
cout << e << d << c << b << a << endl;
}
else if (b > 0)
{
cout << 4 << endl;
cout << b << " " << c << " " << d << " " << e << endl;
cout << e << d << c << b << endl;
}
else if (c > 0)
{
cout << 3 << endl;
cout << c << " " << d << " " << e << endl;
cout << e << d << c << endl;
}
else if (d > 0)
{
cout << 2 << endl;
cout << d << " " << e << endl;
cout << e << d << endl;
}
else if (e > 0)
{
cout << 1 << endl;
cout<< e << endl;
cout << e << endl;
}
}
return 0;
}
0.0分
0 人评分