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:这个程序有以下毛病,请大虾们帮忙指正,本人不胜感激!!!E:\周华健\4545\4545.cpp(21) : error C2106: '=' : left operand must be l-value

Posted by Artemislu at 2004-12-22 20:59:09 on Problem 1700
In Reply To:这个程序有以下毛病,请大虾们帮忙指正,本人不胜感激!!!E:\周华健\4545\4545.cpp(21) : error C2106: '=' : left operand must be l-value Posted by:90401304 at 2004-12-22 20:04:16
其中你写sp=sp??我好疑惑。
貌似你中间在用冒泡排序,但if你错了。
if(*sp+k<*sp+k+1){
      tem=sp+k;
      sp+k=sp+k+1;
      sp+k+1=tem;
}				}
粗看,就知道错了,应该*(sp+k)<*(sp+k+1)
下面也应该改掉:
tem=*(sp+k);
*(sp+k)=*(sp+k+1);
*(sp+k+1)=tem;

> #include <stdio.h>
> #include <malloc.h>
> void main(){
> 	long int N,i,k,j,*sp,time=0,*tem=0;
> 	scanf("%d",&N);
> 	sp=(long int *)malloc(sizeof(long int)*N);
> 	for(i=0;i<N;i++)
> 		scanf("%ld",sp++);
>     sp=sp;
> 	if(N==1)
> 		time=*sp;
> 	else{
> 		for(j=0;j<N-1;j++){
> 			for(k=0;k<N-j;k++){
> 				if(*sp+k<*sp+k+1){
> 					tem=sp+k;
> 					sp+k=sp+k+1;
> 					sp+k+1=tem;
> 				}
> 			}
> 		}		
> 		for(i=0;i<N-2;i++)
> 			time=time+*(sp+i);
> 		time=time+(int)(N/2-1)*(*(sp+1)+*sp);		
> 	}
> 	printf("%ld\n",time);
> }
> 
> 

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