牛牛的数组越位
牛牛的数组越位
http://www.nowcoder.com/questionTerminal/8745d7c3975a4d5aa7f918ec4b4b7d66
简单模拟,对每种情况判断即可
#include<bits/stdc++.h> using namespace std; long long s; long long n, m, p; int a[30000000]; long long x, y, val; int t; int main(){ cin >> t; while (t --){ cin >> n >> m >> p; for (int i = 0; i < m * n; i ++) a[i] = 0; int k = 0; while (p --){ cin >> x >> y >> val; long long gg = x * m + y; if (x < 0 || x >= n || y < 0 || y >= m){ if (gg < n * m && gg >= 0){ a[gg] = val; if (k !=3) k = 1; } else k = 3; } else a[gg] = val; } if(k == 3) cout << "Runtime error" << endl; else{ int s = 0; for (int i = 0; i < m * n; i ++){ s ++; cout << a[i]; if (s == m) cout << endl, s = 0; else cout << " "; } if (! k) cout << "Accepted" << endl; else cout << "Undefined Behaviour" << endl; } } return 0; }