diff --git a/Exercicios/Campo Minado.cpp b/Exercicios/Campo Minado.cpp index 8c3e3e6..e0e83c9 100644 --- a/Exercicios/Campo Minado.cpp +++ b/Exercicios/Campo Minado.cpp @@ -1,20 +1,21 @@ #include +using namespace std; + int main() { int n; - int c[51]; - scanf("%d", &n); - for (int i = 0;i < n;i++) { - scanf("%d", &c[i]); + cin >> n; + int c[n]; + + for (int i = 0; i < n; i++) { + cin >> c[i]; } - for (int i = 0;i < n;i++) { + + for (int i = 0; i < n; i++) { int q = 0; q = q + c[i]; - if (i < n - 1) { - q = q + c[i + 1]; - } - if (i > 0) { - q = q + c[i - 1]; - } - printf("%d\n", q); + if (i < n - 1) q = q + c[i + 1]; + if (i > 0) q = q + c[i - 1]; + + cout << q << endl; } } diff --git "a/Exercicios/C\303\263digo (OBI 2015).cpp" "b/Exercicios/C\303\263digo (OBI 2015).cpp" index 4b79a71..8d9cb2a 100644 --- "a/Exercicios/C\303\263digo (OBI 2015).cpp" +++ "b/Exercicios/C\303\263digo (OBI 2015).cpp" @@ -1,18 +1,23 @@ #include +using namespace std; int main() { int n, cont = 0; - scanf("%d", &n); - int v[n]; - for (int i = 0;i < n;i++) { - scanf("%d", &v[i]); + + cin >> n; + vectorv(n); + + for (int i = 0;i < n; i++) { + cin >> v[i]; } - for (int i = 0;i < n - 2;i++) { + + for (int i = 0;i < n - 2; i++) { if (v[i] == 1) { if (v[i + 1] == 0 && v[i + 2] == 0) { cont++; } } } - printf("%d", cont); + cout << cont; + return 0; } diff --git a/Exercicios/Fita Colorida.cpp b/Exercicios/Fita Colorida.cpp index bf91075..c94ec72 100644 --- a/Exercicios/Fita Colorida.cpp +++ b/Exercicios/Fita Colorida.cpp @@ -1,25 +1,23 @@ #include +#include using namespace std; -int main() -{ + +int main() { int q, c; cin >> q; int v[q]; - for (int i = 0;i < q;i++) { - cin >> v[i]; - } + for (int i = 0;i < q;i++) cin >> v[i]; - for (int i = 0;i < q;i++) { + for (int i = 0; i < q; i++) { if (v[i] == 0) { for (int x = i;x < q;x++) { if (v[x] != 0) { c++; v[x] = min(9, c); - } -else { + } else { c = 0; } } @@ -34,23 +32,15 @@ else { if (v[a] != 0) { c++; - if (v[a] == -1) { - v[a] = min(9, c); - } -else { - v[a] = min(v[a], c); - } - } -else { + v[a] = v[a] == -1 ? min(9, c) : min(v[a], c); + } else { c = 0; } } } } - for (int i = 0;i < q;i++) { - cout << v[i] << " "; - } + for (int i = 0; i < q;i++) cout << v[i] << " "; return 0; } diff --git "a/Exercicios/Tri\303\242ngulos.cpp" "b/Exercicios/Tri\303\242ngulos.cpp" new file mode 100644 index 0000000..38a462f --- /dev/null +++ "b/Exercicios/Tri\303\242ngulos.cpp" @@ -0,0 +1,55 @@ +//https://neps.academy/br/exercise/312 +//Triângulos +#include +#include +using namespace std; + +bool condicao(int a, int b, int c) { + /* + 1 2 1 + | b - c | < a < b + c + | a - c | < b < a + c + | a - b | < c < a + b + */ + int BmenosC = b - c, AmenosC = a - c, AmenosB = a - b; + + BmenosC = BmenosC < 0 ? BmenosC * -1 : BmenosC; + AmenosC = AmenosC < 0 ? AmenosC * -1 : AmenosC; + AmenosB = AmenosB < 0 ? AmenosB * -1 : AmenosB; + + if (BmenosC < a && a < b + c) { + if (AmenosB < c && c < a + b) { + if (AmenosC < b && b < a + c) return true; + else return false; + } else return false; + } else return false; +} + +bool pitagoras(int a, int b, int c) { + // a² = b² + c² + int res = b + c; + return a == res ? true : false; +} + +int main() { + int a, b, c; + + cin >> a >> b >> c; + bool veradeiroOuFalso = condicao(a, b, c); + bool res = pitagoras(pow(a, 2), pow(b, 2), pow(c, 2)); + + if (veradeiroOuFalso) { + if (a == b && b == c) { + cout << "a" << endl; + } + else { + cout << (res ? "r" : "o") << endl; + } + } +else { + cout << "n" << endl; + } + + //cout << endl << pow(a, 2) << " " << pow(b, 2) << " " << pow(c, 2) << " " << pow(b, 2) + pow(c, 2); +} +