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 |
本地编译通不过的代码居然神奇的AC,太假了~#include<stdio.h> #include<string> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int casenum; while(1==scanf("%d",&casenum)) { for(int c=0;c<casenum;c++) { string bin1; string bin2; string tmp; int jinwei=0; int len1; int len2; cin>>bin1>>bin2; len1=bin1.size(); len2=bin2.size(); if(len2<len1) { swap(bin1,bin2); swap(len1,len2); } for(int i=0;i<len2;i++) { if(jinwei) { jinwei=1; bin2[len2-i-1]=bin2[len2-i-1]-'0'+jinwei; jinwei=bin2[len2-i-1]/2; bin2[len2-i-1]=bin2[len2-i-1]%2+'0'; } if(len1-i-1>=0) { bin2[len2-i-1]=bin2[len2-i-1]-'0'+bin1[len1-i-1]-'0'; jinwei+=bin2[len2-i-1]/2; bin2[len2-i-1]=bin2[len2-i-1]%2+'0'; } if(len2-i-1==0&&jinwei) { bin2.insert(0,‘1’);//这里是有错的哦~ } } len2=bin2.size(); while(bin2[0]=='0') { len2--; if(len2==0) break; bin2.erase(0,1); } cout<<c+1<<" "<<bin2<<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