#include <stdio.h> int main() { int N; while (scanf("%d", &N) == 1) { int grid[2][99]; int i, j, k; for (i = 0; i < N; i++) { scanf("%d", &grid[0][i]); } for (i = 0; i < N; i++) { scanf("%d", &grid[1][i]); } int count = 0; for (i = N - 1; i >= 0; i--) { for (j = 0; j < N; j++) { if (grid[0][j] == grid[1][i]) { for (k = j; k < i; k++) { int temp = grid[0][k + 1]; grid[0][k + 1] = grid[0][k]; grid[0][k] = temp; count++; } break; } } } printf("%d\n", count); } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2014年7月7日
UVa 12488 - Start Grid
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言