30分,捞我!!!!
查看原帖
30分,捞我!!!!
1066396
szm111213楼主2024/10/13 09:36
#include<bits/stdc++.h>
using namespace std;
string chai(int n)
{
	string s = "";
	while(n > 0)
	{
		s += (n % 2 == 0 ? "0" : "1");
		n /= 2;
	}
	return s;
}
int main()
{
	int n;
	cin >> n;
	if(n % 2 != 0 || n <= 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	string a = chai(n);
	for(int i = a.size() - 1; i > 0 - 1; i --)
	{
		if(a[i] == '1')
		{
			cout << a.size() - i << " ";
			for(int j = i - 1; j > 0 - 1; j --)
			{
				if(a[j] == '1')
				{
					cout << "2 ";
				}
				else
				{
					cout << "1 ";
				}
			}
			cout << "2" << endl;
			return 0;
		}
	}
	return 0;
}
2024/10/13 09:36
加载中...