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 |
关于getline的巨大疑问???虚心求教#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator