Advertisement
mariacv

Untitled

Oct 30th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void row(int a, int b, int n, int array[9][9])
  6. {
  7. int temp[9];
  8. int i;
  9.  
  10. for(i = 0; i < n; i++)
  11. {
  12. temp[i] = array[a][i];
  13. array[a][i] = array[b][i];
  14. array[b][i] = temp[i];
  15. }
  16. }
  17. void col(int a, int b, int n, int array[9][9])
  18. {
  19. int temp[9];
  20. int i;
  21.  
  22. for(i = 0; i < n; i++)
  23. {
  24. temp[i] = array[i][a];
  25. array[i][a] = array[i][b];
  26. array[i][b] = temp[i];
  27. }
  28. }
  29. void inc(int array[9][9], int n)
  30. {
  31. int i, j;
  32.  
  33. for(i = 0; i < n; i++)
  34. {
  35. for(j = 0; j < n; j++)
  36. {
  37. array[i][j] = array[i][j] + 1;
  38. if(array[i][j] == 10)
  39. {
  40. array[i][j] = 0;
  41. }
  42. }
  43. }
  44. }
  45. void dec(int array[9][9], int n)
  46. {
  47. int i, j;
  48.  
  49. for(i = 0; i < n; i++)
  50. {
  51. for(j = 0; j < n; j++)
  52. {
  53. array[i][j] = array[i][j] - 1;
  54. if(array[i][j] == -1)
  55. {
  56. array[i][j] = 9;
  57. }
  58. }
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. int t;
  65. int n, m;
  66. int i, j;
  67. int array[9][9];
  68. char func[51];
  69. int a, b;
  70.  
  71. scanf("%d", &t);
  72.  
  73. for(i = 0; i < t; i++)
  74. {
  75. scanf("%d", &n);
  76.  
  77. for(i = 0; i < n; i++)
  78. {
  79. for(j = 0; j < n; j++)
  80. {
  81. scanf("%d", &array[i][j]);
  82. }
  83. }
  84.  
  85. scanf("%d", &m);
  86.  
  87. for(i = 0; i < m; i++)
  88. {
  89. scanf("%s", func);
  90.  
  91. if(strcmp (func, "row"))
  92. {
  93. scanf("%d%d", &a, &b);
  94. row(a, b, n, array);
  95. }
  96. if(strcmp (func, "col"))
  97. {
  98. scanf("%d%d", &a, &b);
  99. col(a, b, n, array);
  100. }
  101. if(strcmp (func, "inc"))
  102. {
  103. inc(array, n);
  104. }
  105. if(strcmp (func, "dec"))
  106. {
  107. dec(array, n);
  108. }
  109. }
  110. }
  111.  
  112.  
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement