online_judge_1208
2016-05-02 20:08
330 查看
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { char str[1020]; int a[1020],tBit[1020],res[1020]; int aBit[4000]; int len,lena,i,j,remain; bool isNotZero; while(cin>>str) { memset(a, 0, sizeof(a)); memset(aBit, 0, sizeof(aBit)); memset(tBit, 0, sizeof(tBit)); memset(res, 0, sizeof(res)); len = strlen(str); i = 0; while(str[i] == '0' && i<len-1) ++i; j=0; while(i<len) { a[j++] = str[i++] - '0'; } len = j; if(len==1 && a[0] == 0) { cout<<0<<endl; continue; } lena = 0; isNotZero = true; while(isNotZero) { remain = 0; isNotZero = false; for(i=0; i<len; ++i) { a[i] += remain*10; remain = a[i]%2; a[i] = a[i]/2; if(a[i] > 0) isNotZero = true; } aBit[lena++] = remain; } tBit[0] = 1; for(i=lena-1; i>=0; i--) { if(aBit[i]) { for(j=0; j<1020; ++j) { res[j] += tBit[j]; } for(j=0; j<1019; ++j) { res[j+1] += res[j]/10; res[j] = res[j]%10; } } for(j=0; j<1020; ++j) tBit[j] *= 2; for(j=0; j<1019; ++j) { tBit[j+1] += tBit[j]/10; tBit[j] %= 10; } } j=1019; while(j>=0 && res[j]==0) --j; for(i=j; i>=0; --i) cout<<res[i]; cout<<endl; } } /* #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct bigInt { char digit[1001]; int len1; bigInt() { len1 = 0; memset(digit,0,sizeof(digit)); } void Set(char *st) { strcpy(digit,st); len1 = strlen(digit); } bool operator % (int i) const { if(len1==0) return false; return (digit[0]-'0')%i; } bigInt operator / (int number) { bigInt b; int i,t; int value = 0; b.len1 = len1; if((digit[len1-1]-'0'+value)<number) { b.len1--; } for(i=len1-1; i>=0; --i) { t = digit[i]-'0'+10*value; b.digit[i] = t/number + '0'; value = t%number; } b.digit[b.len1] = 0; return b; } bigInt operator * (const int number) { int value = 0; int i,t; bigInt b; for(i=0; i<len1; ++i) { t = (digit[i]-'0')*number+value; b.digit[b.len1++] = t%10 + '0'; value = t/10; } if(value > 0) b.digit[b.len1++] = value + '0'; b.digit[b.len1] = 0; return b; } bigInt operator ++() { int value = 1; for(int i=0; i<this->len1; ++i) { this->digit[i] = (this->digit[i]-'0'+value)%10+'0'; value = (this->digit[i]-'0'+value)/10; if(value==0) break; } if(value>0) this->digit[len1++] = value + '0'; return *this; } void PrintEight() { for(int i=len1-1; i>=0; i--) cout<<digit[i]; cout<<endl; } }; int main() { char str[1002]; char st[4000]; char c; int len,i,j; int ll; bigInt a; while(cin>>str) { len = strlen(str); i=0;j=len-1; while(i<j) { c = str[i]; str[i] = str[j]; str[j] = c; i++; j--; } while(str[len-1]=='0') len--; str[len] = 0; if((len==1 && str[0]=='0')||len==0) { cout<<"0"<<endl; continue; } a.Set(str); bigInt b; ll = 0; while(a.len1) { if(a%2) st[ll] = '1'; else st[ll] = '0'; ll++; b = a/2; a = b; } st[ll] = 0; bigInt cc,d; char ss[2] = "1"; cc.Set(ss); i=0; j=ll-1; while(i<j) { c = st[i]; st[i] = st[j]; st[j] = c; i++; j--; } while(st[ll-1]=='0') ll--; for(i=ll-2; i>=0; --i) { d = cc*2; if(st[i] == '1') ++d; cc = d; //cc.PrintEight(); } cc.PrintEight(); } return 0; } */
这个题目真是蛋疼……
注释部分提交不了。。不知道错哪里了………………
相关文章推荐
- 解决UDP服务器并发困难
- 欧几里得算法求最大公约数的递归和非递归实现
- java的静态代理
- List--LinkedList(浅识)二
- Volley相关知识
- Python爬虫折腾纪录
- 待整理内容
- nyoj_42 一笔画问题
- 3. Longest Substring Without Repeating Characters
- 动态规划——最少硬币问题
- hdu 5677 ztr loves substring 多重背包
- Android Studio 文件名颜色代表含义
- elk搭建完整搭建【篇1】
- Golang实现红黑树
- iOS中黄色文件夹和蓝色文件夹的区别
- 文章标题
- 默认参数与占位符参数
- Asp.net WebApi 项目示例(增删改查)
- 【AKOJ】1313-DNF又爆满啦
- ubuntu 的使用