Advertisement
DASBD72

NTHU12891

Oct 11th, 2020 (edited)
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include<stdio.h>
  2. //Longest Row Vector
  3. int main()
  4. {
  5.     printf("start\n");
  6.     int m, n, K;
  7.     short arr[1005][1005];
  8.     scanf("%d %d %d", &m, &n, &K);
  9.     // read input
  10.     for(int row = 0; row < m; row++)
  11.     for(int col = 0; col < n; col++)
  12.     {
  13.         scanf("%d", &arr[row][col]);
  14.     }
  15.     // read tasks
  16.     while(K--)
  17.     {
  18.         int cmd, i, j;
  19.         scanf("%d%d%d", &cmd, &i, &j);
  20.         if(cmd == 0)for(int col = 0; col < n; col++)
  21.         {
  22.             //swap
  23.             arr[i][col] += arr[j][col];
  24.             arr[j][col] = arr[i][col] - arr[j][col];
  25.             arr[i][col] = arr[i][col] - arr[j][col];
  26.         }
  27.         else for(int col = 0; col < n; col++) arr[i][col] += arr[j][col];
  28.     }
  29.  
  30.     int max = 0, rowidx;
  31.     for(int row = 0, tmp = 0; row < m; row++)
  32.     {
  33.         for(int col = 0; col < n; col++)
  34.         {
  35.             //count sum of square
  36.             tmp += arr[row][col] * arr[row][col];
  37.         }
  38.         if(tmp > max)
  39.         {
  40.             //replace max and rowidx to the bigger one
  41.             max = tmp;
  42.             rowidx = row;
  43.         }
  44.     }
  45.     for(int col = 0; col < n; col++)
  46.     {
  47.         //output answer
  48.         col == n-1 ? printf("%d\n", arr[rowidx][col]) : printf("%d ", arr[rowidx][col]);
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement