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

Re:求高人帮我看一下~~!!测试没问题!提交就错误答案 ~~不胜感谢!!

Posted by 330332 at 2008-11-28 18:48:02 on Problem 2845 and last updated at 2008-11-28 18:49:04
In Reply To:求高人帮我看一下~~!!测试没问题!提交就错误答案 ~~不胜感谢!! Posted by:zhouniandi at 2006-08-17 11:38:44
我把你的代码运行了一下,有Compile Error.将for(int j = ……)中j的定义放在外边就过了,否则下面的j找不到。
#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;
		int j = 0;/*************/
		for(j=0;j<=81;j++){
			if(c_fbit[j]==0){
				k=j;
			}
		}
		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;
			}
		}
		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 cleanup(Case *d){
	for(int i=0;i<=81;i++){
			d->fbit[i]=d->ebit[i]=d->rbit[i]='0';
		}
}
int main(){
	Case *d;
	int i=0, j = 0;/**************/
	cin>>i;
	d = (class Case *)malloc(i*sizeof(class Case));
	for(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();
	}
	return 0;
}

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