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

关于getline的巨大疑问???虚心求教

Posted by simon_cqdx at 2008-01-19 00:20:09 on Problem 2316
#include<iostream.h>
#include<string.h>
main()
{int a[15],i,l;
 char p[15];
 memset(a,'\0',sizeof(a));
 while (cin.getline(p,15))
  {l=strlen(p);
   for (i=0;i<=l-1;i++)
     a[i]=(a[i]+p[i]-48)%10;
  }
 for (i=0;i<=l-1;i++) cout<<a[i];
 cout<<endl;
}


为什么这么简单的题一直WA呢?

而以下这个代码就能AC,有什么区别呢?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char num[15];
char total[15];
int main()
{int i,len,temp;
    gets(total);    
    while(gets(num)!=0)
	{len=strlen(num);
	  for(i=0;i<len;i++)
            total[i]=(total[i]+num[i]-'0'-'0')%10+'0';	
	}
	printf("%s",total);
	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