求助......
查看原帖
求助......
522847
NCO_Dongfeng_MS楼主2022/3/24 16:23

在本地都能过,可为什么在洛谷上就只有30分呢?

代码:

#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
stack<int>S;
int n;
int len;
int book=1;
//int ans[25]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32786,65536,131072,262144,524288,1048576,2097152,4194304,8388608};
int main(){
	cin>>n;
	if(n&1==1){
		cout<<"-1";
		return 0;
	}
	while(n){
		if(n&1==1){
			S.push(1);
		}else{
			S.push(0);
		}
		len++;
		n>>=1;
	}
	for(int i=len-1;i>=0;i--){ 
		if(S.top()==1){
			cout<<book<<' ';
		}
		S.pop();
		book<<=1;
	}
	return 0;
}
2022/3/24 16:23
加载中...