Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstdio>
- using namespace std;
- int m[1010][1010];
- int p, q, con, n;
- void down(){
- while(p + 1 < n && q + 1 < n){
- p++;
- q++;
- printf("%d ",m[p][q]);
- con++;
- }
- }
- void up(){
- while(p - 1 >= 0 && q - 1 >= 0){
- p--;
- q--;
- printf("%d ",m[p][q]);
- con ++;
- }
- }
- int main(){
- int t , ts = 0;
- cin >> t;
- while(t--){
- con = 0;
- cin >> n;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- cin >> m[i][j];
- }
- }
- printf("Case #%d: ", ++ts);
- con = 0;
- p = n-1;
- q = 0;
- con++;
- printf("%d ",m[p][q]);
- while(con != n*n){
- if(p + 1 < n && q + 1 < n)down();
- if(q+1 < n){
- q = q+1;
- printf("%d ",m[p][q]);
- con ++;
- }
- else if(p - 1 >= 0){
- p = p - 1;
- printf("%d ",m[p][q]);
- con++;
- }
- if(p - 1 >= 0 && q - 1 >= 0)up();
- if(p - 1 >= 0){
- p = p - 1;
- printf("%d ",m[p][q]);
- con++;
- }else if(q + 1 < n){
- q = q + 1;
- printf("%d ",m[p][q]);
- con++;
- }
- }printf("\n");
- }return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement