Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- const int SIZE = 1e3;
- int row_st[SIZE],N;
- int main(){
- scanf("%d",&N);
- printf("%d\n",N);
- int now=0;
- for(int i=0;i<N;i+=2){
- row_st[i]=now;
- now+=N;
- }
- for(int i=1;i<N;i+=2){
- row_st[i]=now;
- now+=N;
- }
- int ll=row_st[0],rr=row_st[0]+N-1;
- for(int j=0;j<N;j++){
- int v;
- if(j<3)v=ll++;
- else if(j%4!=2)v=rr--;
- else v=ll++;
- printf("%d%c",v," \n"[j==N-1]);
- }
- for(int i=1;i<N-1;i++){
- if(i%2==1){
- for(int j=0;j<N;j++)printf("%d%c",row_st[i]+j," \n"[j==N-1]);
- }
- else{
- for(int j=0;j<N;j++)printf("%d%c",row_st[i]+N-1-j," \n"[j==N-1]);
- }
- }
- ll=row_st[N-1],rr=row_st[N-1]+N-1;
- for(int j=0;j<N;j++){
- int v;
- if(j%4==1||j%4==2)v=rr--;
- else v=ll++;
- printf("%d%c",v," \n"[j==N-1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment