Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

提交就错误答案~~郁闷~

Posted by zhouniandi at 2006-08-17 10:43:30 on Problem 2845
In Reply To:Re:000000+000000=0 Posted by:ice_lemon at 2006-08-03 03:38:46
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
class Case
{
public:
	char c_fbit[82];
	char fbit[82];
	char c_ebit[82];
	char ebit[82];
	char rbit[83];
	void init(){
		cin>>c_fbit;
		cin>>c_ebit;
		inversion();
	}
	void inversion(){
		int k=0;
		for(int j=0;j<=81;j++){
			if(c_fbit[j]==0){
				k=j;
			}
		}
		fbit[k] = '0';
		int i=0;
		while(k!=0){
			fbit[81-k]=c_fbit[i];
			i++;
			k--;
		}
		k=0;
		for(j=0;j<=81;j++){
			if(c_ebit[j]==0){
				k=j;
			}
		}
		ebit[k] = '0';
		i=0;
		while(k!=0){
			ebit[81-k]=c_ebit[i];
			i++;
			k--;
		}
	}
	void addition(){
		int rbit_index=81;
		char temp='0';
		for(int j=80;j>=0;j--){
			if(temp=='1'){
				if(fbit[j]=='1'&&ebit[j]=='1'){
					rbit[rbit_index]='1';
					rbit_index--;
					temp='1';
					continue;
				}else if(fbit[j]=='1'&&ebit[j]=='0'||fbit[j]=='0'&&ebit[j]=='1'){
					rbit[rbit_index]='0';
					rbit_index--;
					temp='1';
					continue;
				}else if(fbit[j]=='0'&&ebit[j]=='0'){
					rbit[rbit_index]='1';
					rbit_index--;
					temp='0';
					continue;
				}
			}else{
				if(fbit[j]=='1'&&ebit[j]=='1'){
					rbit[rbit_index]='0';
					rbit_index--;
					temp='1';
					continue;
				}else if(fbit[j]=='1'&&ebit[j]=='0'||fbit[j]=='0'&&ebit[j]=='1'){
					rbit[rbit_index] = '1';
					rbit_index--;
					temp='0';
					continue;
				}else if(fbit[j]=='0'&&ebit[j]=='0'){
					rbit[rbit_index] = '0';
					rbit_index--;
					temp='0';
					continue;
				}
			}
		}
		if(temp=='1'){
			rbit[rbit_index] = '1';
			temp='0';
			rbit_index--;
		}
	}
	void display(){
		for(int i=0;i<=81;i++){
			if(rbit[i]=='1'){
				for(int j=i;j<=81;j++){
					cout<<rbit[j];
				}
				cout<<endl;
				return;
			}
		}
		cout<<'0'<<endl;
	}
	void display1(){
		for(int i=0;i<81;i++){
			cout<<fbit[i];
		}
		cout<<endl;
		for(i=0;i<81;i++){
			cout<<ebit[i];
		}
		cout<<endl;
		for(i=0;i<=81;i++){
			cout<<rbit[i];
		}
		cout<<endl;
	}
};
void cleanup(Case *d){
	for(int i=0;i<=81;i++){
			d->fbit[i]=d->ebit[i]=d->rbit[i]='0';
		}
}
void main(){

	Case *d;
	int i=0;
	cin>>i;
	d = (class Case *)malloc(i*sizeof(class Case));
	for(int j=0;j<i;j++){
		cleanup(&d[j]);
		d[j].init();
		d[j].addition();
	}
	for(j=0;j<i;j++){
		cout<<j+1<<' ';
		d[j].display();
		
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator