Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
分情况讨论即可#include <iostream> using namespace std; #include <vector> int mypow(int a,int t) { int res=1; for(int i=1;i<=t;i++) res*=a; return res; } int main() { char ins[5]; vector<int> v; while(scanf("%s",ins)) { v.clear(); if(ins[0]=='0' && ins[1]=='0' && ins[3]=='0') break; int num=((ins[0]-'0')*10+ins[1]-'0')*mypow(10,ins[3]-'0'); int out=0; while(num>1) { if(num%2==0 && out==0) { v.push_back(0); num=num/2; } else if(num%2==1&&out==0) { num=num/2+1; v.push_back(0); out=1; } else if(num%2==0&&out==1) { v.push_back(1); num=num/2; } else { v.push_back(1); num=num/2; out=0; } } while(!v.empty()) { int temp=v.back(); v.pop_back(); if(temp==0) { num=num+num-1; } else { num=num+num; } } cout << num << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator