Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- # include <stdlib.h>
- /*
- struct PrintTornado{
- };
- */
- int** ConstructTor(int n){
- int** ms = malloc(n * sizeof(int*) );
- int i = 0;
- while(i < n){
- ms[i] = malloc(n * sizeof(int) );
- i++;
- }
- return ms;
- }
- void go(int** Tornado, int num, int X, int Y, int direction){
- int count = 0;
- int steps = 0;
- int move = 0;
- int i;
- while(count < num * num){
- if(direction == 0){
- steps = 1 + (move / 2);
- for(i = 0; i < steps; i++){
- printf("%d", Tornado[Y][X--] );
- count++;
- }
- move++;
- direction = 1;
- }else if(direction == 1){
- steps = 1 + (move / 2);
- for(i = 0; i < steps; i++){
- printf("%d", Tornado[Y--][X] );
- count++;
- }
- move++;
- direction = 2;
- }else if(direction == 2){
- steps = 1 + (move / 2);
- for(i = 0; i < steps; i++){
- printf("%d", Tornado[Y][X++] );
- count++;
- }
- move++;
- direction = 3;
- }else{
- steps = 1 + (move / 2);
- for(i = 0; i < steps; i++){
- printf("%d", Tornado[Y++][X] );
- count++;
- }
- move++;
- direction = 0;
- }
- }
- }
- int main(){
- int num;
- int direction;
- while(scanf("%d", &num) != EOF){
- int** Tornado = ConstructTor(num);
- scanf("%d", &direction);
- // 0代表左 、1代表上 、2代表右 、3代表下
- int i = 0;
- while(i < num){
- int j = 0;
- while(j < num){
- scanf("%d", &Tornado[i][j] );
- j++;
- }
- i++;
- }
- int Xin = (num / 2);
- int Yin = (num / 2);
- go(Tornado, num, Xin, Yin, direction);
- printf("\n");
- }
- return 0;
- }
- //(2ms, 116KB)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement