https://www.luogu.com.cn/record/201380587
P1010 [NOIP 1998 普及组] 幂次方
在洛谷上面AC了,但是上传到另一个OJ就WA了,有一个测试点没过。
代码:
#include<iostream>
using namespace std;
void S(int n) {
if(n==0)cout<<"0";
else if(n==1)cout<<"2(0)";
else if(n==2)cout<<"2";
else {
bool first=true;
for(int i=14; i>=0; i--) {
if((1<<i)<=n) {
if(!first)cout<<"+";
if(i==1)cout<<"2";
else {
cout<<"2(";
S(i);
cout<<")";
}
n-=(1<<i);
first=false;
}
}
}
}
int main() {
int n;
cin>>n;
S(n);
return 0;
}
另一OJ评测记录:https://boyacoding.cn/record/67a2f0180d81591877805938
题目链接:https://boyacoding.cn/p/A0094