求该程序代码!!!急求!

来源:百度知道 编辑:UC知道 时间:2024/05/12 00:57:04
Problem D:exponential form

Input file: form.in

Output file: standard output

Time limit: 5 seconds

Memory limit: 64megabytes

Every positive number can be presented b the exponential form.for example,

137=

Let’s present by the form a(b). then ,137 is presented by 2(7)+2(3)+2(0).

Since 7= and 3= ,137 is finally presented by 2(2(2)+2+2(0))+2(2+2(0))+2(0).

Given a positive number n , your task is to present n with the exponential form which only contains the digits 0 and 2.

Input:

The input file contains a positive integer n(n<=20000)

Output:

You should output the exponential form of n on a single line. Note that, there should not be any additional white spaces in the line.

就是指数问题
c或者c++吧

C++,不带文件操作:
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> iVector;
typedef unsigned int uInt;
//----------------------------------------------------------------------
void int2bin(int var,iVector& t)
{
if (var==1){
t.push_back(1);
}else{
if (var%2==0){
t.push_back(0);
}else{
t.push_back(1);
}
int2bin(var/2,t);
}
}
//----------------------------------------------------------------------
void display(int x)
{
vector<int> a;
int2bin(x,a);
uInt m=a.size();
for (uInt i=0;i<m;i++){
if (a[i]==1){
if (i==0 || i==2){
printf("2(%d)",i);
}else if ( i==1){
cout<<"2";
}else{
cout<<"2(";
display(i);
cout<<")";
}
if (i!=m-1) cout<<&