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 |
请教:两份算法完全相同的代码,区别在哪里??// by qiqilrq, wrong answer #include <iostream> #include <string.h> using namespace std; char t[210]; int main() { int i,j,row,col; while (cin>>col && col>0) { cin>>t; row=strlen(t)/col; for(i=0;i<row;i++) { if(i%2==1) //row is odd { for(j=0;j<=col/2;j++) { char tmp=t[j+i*col]; t[j+i*col] = t[col-j-1+i*col]; t[col-j-1+i*col] = tmp; } } } // cout<<t<<endl; for(i=0;i<col;i++) for(j=0;j<row;j++) cout<<t[i+j*col]; cout<<endl; } return 0; } /* // by coffeeandtea, accepted #include <iostream.h> #include <string.h> int main() { int col; int i,j; while(cin>>col&&col) { char a[207]; cin>>a;//gets(a) get a wa but cin>>a gets AC Why?? int len=strlen(a); int row=len/col; for(i=0;i<row;i++) for(j=0;j<col/2;j++) { if(i%2==1) { int temp=a[i*col+j]; a[i*col+j]=a[i*col+col-j-1]; a[i*col+col-j-1]=temp; } } for(i=0;i<col;i++) for(j=0;j<row;j++) { cout<<a[i+j*col]; } cout<<endl; } return 0; } */ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator