fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 50;
  5. const int MAX_VAL = 10000;
  6. int freq[MAX_VAL];
  7.  
  8. int main() {
  9. int n, mt[MAX_SIZE + 1][MAX_SIZE + 1];
  10. cin >> n;
  11. int highVal = 1;
  12. for (int i = 1; i <= n; ++i) {
  13. for (int j = 1; j <= n; ++j) {
  14. cin >> mt[i][j];
  15. ++freq[mt[i][j]];
  16. if (mt[i][j] >= highVal) {
  17. highVal = mt[i][j]; // 4
  18. }
  19. }
  20. }
  21. int flag = 1;
  22. for (int i = 1; i <= highVal || i <= n; ++i) {
  23. if (freq[i] < 1 && i <= n) {
  24. flag = 0;
  25. }
  26. //cout << freq[i] <<" " << i <<"\n";
  27. }
  28.  
  29. int highApar = 0, saveVal = highVal;
  30.  
  31. for (int i = n + 1; i <= highVal; ++i) {
  32. if (freq[i] >= highApar ) { // && saveVal > n
  33. highApar = freq[i];
  34. saveVal = i;
  35. }
  36.  
  37. }
  38. if (highVal <= n) {
  39. saveVal = 0;
  40. }
  41.  
  42. if (flag == 1) {
  43. cout << "DA!\n" ;
  44. if (saveVal != 0) {
  45. cout << saveVal;
  46. } else {
  47. cout << "NU!";
  48. }
  49. } else {
  50. cout << "NU!\n";
  51. if (saveVal != 0) {
  52. cout << saveVal;
  53. } else {
  54. cout << "NU!";
  55. }
  56. }
  57.  
  58.  
  59.  
  60. // cout << flag << " "<< saveVal;;
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5320KB
stdin
5
1 2 4 3 4
1 2 4 4 4
1 2 4 3 4
1 2 4 3 4
1 2 4 3 4

4
1 2 3 4
1 2 3 4 
1 2 3 4 
1 2 3 4 


4
1 2 6 4
55 55 63 12
63 55 55 1
4 3 2 1

4
1 2 3 5
1 2 3 4 
1 2 3 4 
1 2 3 4 

4
1 2 3 4
55 63 63 12
63 55 55 1
4 3 2 1

4
1 2 3 5 
1 2 3 4 
1 2 3 4 
1 2 3 4 

4
1 2 3 4
55 63 63 12
63 55 55 1
4 3 2 1


4
1 2 3 5 
1 2 3 4 
1 2 3 4 
1 2 3 4 
stdout
NU!
NU!