@LevMckinney/

nailingit

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>

int main()
{
    int n;
    std::cin >> n;
    int input[n] = {0};
    int fenceLengthByHightTable[4001] = {0};

    for(int i = 0; i < n; ++i)
    {
        std::cin >> input[i];
        std::cout << input[i] << "\n";
    }


    bool coltest;
    bool rowtest;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < i; ++j)
        {
            coltest = false;
            rowtest = false;

            for(int k = i - 1; k > j; --k)
            {
                if(input[i] == input[k])
                {
                    coltest = true;
                }
            }

            if(!coltest)
            {
              for(int k = j - 1; k >= 0; --k)
              {
                  if(input[j] == input[k])
                  {
                      rowtest = true;
                  }
              }
            }

            if(!rowtest && !coltest)
            {
                std::cout <<  input[i] + input[j] << " ";
                fenceLengthByHightTable[input[i] + input[j]]++;
            }
            else
            {
              std::cout <<  "X ";
            }
        }
        std::cout << "\n";
    }

    std::cout << "\n";

    int longestFence = 0;
    int numberOfFences = 0;

    for(int i = 0; i < 4001; ++i)
    {
        if(fenceLengthByHightTable[i] > 0)
        {
          std::cout << "[ Lenght:"  << fenceLengthByHightTable[i] << ", Hight:" << i << "]";
        }
        if(fenceLengthByHightTable[i] > longestFence)
        {
            longestFence = fenceLengthByHightTable[i];
            numberOfFences = 1;
        }
        else if(fenceLengthByHightTable[i] == longestFence)
        {
            numberOfFences++;
        }
    }
    
    std::cout << longestFence << " " << numberOfFences;
}