From 166e819060068756167d5f739dc1c1d3e2c7e5da Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2019 19:04:24 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20task?= =?UTF-8?q?=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/cpp/t01_max3.cpp | 16 +++++++++++++--- src/main/cpp/t02_triangle.cpp | 16 +++++++++++++--- src/main/cpp/t03_equal3.cpp | 22 +++++++++++++++++++--- src/main/cpp/t04_chess_rook.cpp | 8 ++++++-- src/main/cpp/t05_chess_king.cpp | 8 ++++++-- src/main/cpp/t06_chess_bishop.cpp | 9 +++++++-- src/main/cpp/t07_chess_queen.cpp | 9 +++++++-- src/main/cpp/t08_chess_knight.cpp | 8 ++++++-- src/main/cpp/t09_choco.cpp | 9 +++++++-- src/main/cpp/t10_sort3.cpp | 23 ++++++++++++++++++++--- src/main/cpp/t11_boxes.cpp | 30 +++++++++++++++++++++++++++--- 11 files changed, 131 insertions(+), 27 deletions(-) diff --git a/src/main/cpp/t01_max3.cpp b/src/main/cpp/t01_max3.cpp index 5d09aaa2..398f2104 100644 --- a/src/main/cpp/t01_max3.cpp +++ b/src/main/cpp/t01_max3.cpp @@ -16,7 +16,17 @@ #include using namespace std; - +int sorted(int *array, int size){ + int max = *array; + for (int i = 0; i < size; ++i) { + if (*(array + i) > max) + max = *(array + i); + else continue; + } + return max; +} int t01_max3() { - -}; \ No newline at end of file + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + cout << sorted(a,3); +}; diff --git a/src/main/cpp/t02_triangle.cpp b/src/main/cpp/t02_triangle.cpp index f50c09cb..18f74af3 100644 --- a/src/main/cpp/t02_triangle.cpp +++ b/src/main/cpp/t02_triangle.cpp @@ -17,7 +17,17 @@ #include using namespace std; - +bool check(int a, int b, int c){ + if (c < (a + b)) + return true; + else + return false; + +} int t02_triangle() { - -}; \ No newline at end of file + int a, b, c; + cin >> a >> b >> c; + if (check(a,b,c) && check(a,c,b) && check(b,c,a)) + cout << "YES"; + else cout << "NO"; +}; diff --git a/src/main/cpp/t03_equal3.cpp b/src/main/cpp/t03_equal3.cpp index c9e661de..dc33c18f 100644 --- a/src/main/cpp/t03_equal3.cpp +++ b/src/main/cpp/t03_equal3.cpp @@ -17,7 +17,23 @@ #include using namespace std; - +int check(int *array, int start = 0, int size = 3){ + int count = 0; + for (int i = start; i < size; ++i) + if (*(array + start) == *(array + i)) + count++; + return count; +} int t03_equal3() { - -}; \ No newline at end of file + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + if (check(a) == 3) + cout << 3; + else if (check(a) == 2) + cout << 2; + else { + if (check(a,1) == 2) + cout << 2; + else cout << 1; + } +}; diff --git a/src/main/cpp/t04_chess_rook.cpp b/src/main/cpp/t04_chess_rook.cpp index fd6bb663..d4ddf673 100644 --- a/src/main/cpp/t04_chess_rook.cpp +++ b/src/main/cpp/t04_chess_rook.cpp @@ -19,5 +19,9 @@ using namespace std; int t04_chess_rook() { - -}; \ No newline at end of file + int x1,y1,x2,y2; + cin>>x1>>y1>>x2>>y2; + if (x1==x2 || y1==y2) + cout<<"YES"; + else cout<<"NO"; +}; diff --git a/src/main/cpp/t05_chess_king.cpp b/src/main/cpp/t05_chess_king.cpp index e3f93bbd..5a745dfc 100644 --- a/src/main/cpp/t05_chess_king.cpp +++ b/src/main/cpp/t05_chess_king.cpp @@ -20,5 +20,9 @@ using namespace std; int t05_chess_king() { - -}; \ No newline at end of file + int x1,y1,x2,y2; + cin>>x1>>y1>>x2>>y2; + if (abs(x1-x2)<2 && abs(y1-y2)<2) + cout<<"YES"; + else cout<<"NO"; +}; diff --git a/src/main/cpp/t06_chess_bishop.cpp b/src/main/cpp/t06_chess_bishop.cpp index cbcc1f36..3ef45a94 100644 --- a/src/main/cpp/t06_chess_bishop.cpp +++ b/src/main/cpp/t06_chess_bishop.cpp @@ -20,5 +20,10 @@ using namespace std; int t06_chess_bishop() { - -}; \ No newline at end of file + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (abs(x1 - x2) == abs(y1 - y2)) + cout << "YES"; + else + cout << "NO"; +}; diff --git a/src/main/cpp/t07_chess_queen.cpp b/src/main/cpp/t07_chess_queen.cpp index c43f46dc..5b91f2a5 100644 --- a/src/main/cpp/t07_chess_queen.cpp +++ b/src/main/cpp/t07_chess_queen.cpp @@ -29,5 +29,10 @@ using namespace std; int t07_chess_queen() { - -}; \ No newline at end of file + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (abs(x1 - x2) == abs(y1 - y2) || x1 == x2 || y1 == y2) + cout << "YES"; + else + cout << "NO"; +}; diff --git a/src/main/cpp/t08_chess_knight.cpp b/src/main/cpp/t08_chess_knight.cpp index f4b85cd9..fc5c37f3 100644 --- a/src/main/cpp/t08_chess_knight.cpp +++ b/src/main/cpp/t08_chess_knight.cpp @@ -29,5 +29,9 @@ using namespace std; int t08_chess_knight() { - -}; \ No newline at end of file + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (abs(x1 - x2) == 1 && abs(y1 - y2) == 2 || abs(x1 - x2) == 2 && abs(y1 - y2) == 1) + cout << "YES"; + else cout << "NO"; +}; diff --git a/src/main/cpp/t09_choco.cpp b/src/main/cpp/t09_choco.cpp index 33e51674..489cee76 100644 --- a/src/main/cpp/t09_choco.cpp +++ b/src/main/cpp/t09_choco.cpp @@ -27,5 +27,10 @@ using namespace std; int t09_choco() { - -}; \ No newline at end of file + int N, M, K; + cin >> N >> M >> K; + if (K < N * M && ((K % N == 0) || (K % M == 0))) + cout << "YES"; + else + cout << "NO"; +}; diff --git a/src/main/cpp/t10_sort3.cpp b/src/main/cpp/t10_sort3.cpp index 7a8d2476..419876bc 100644 --- a/src/main/cpp/t10_sort3.cpp +++ b/src/main/cpp/t10_sort3.cpp @@ -17,7 +17,24 @@ #include using namespace std; - +void swap(int &a, int &b){ + a = a^b; + b = a^b; + a = a^b; +} +void sort(int *array, int size = 3){ + for (int i = 0; i < size; ++i) { + if (*(array + i) > *(array + i+1)) + swap(*(array + i), *(array + i+1)); + } +} int t10_sort3() { - -}; \ No newline at end of file + int a[3]; + for (int i = 0; i < 3; ++i) { + cin >> a[i]; + } + sort(a); + for (int i = 0; i < 3; ++i) { + cout << a[i] << ' '; + } +}; diff --git a/src/main/cpp/t11_boxes.cpp b/src/main/cpp/t11_boxes.cpp index 3671cc32..0f8070c7 100644 --- a/src/main/cpp/t11_boxes.cpp +++ b/src/main/cpp/t11_boxes.cpp @@ -35,7 +35,31 @@ #include using namespace std; - +void swap(int &a, int &b){ + a = a^b; + b = a^b; + a = a^b; +} int t11_boxes() { - -}; \ No newline at end of file + int a1,b1,c1,a2,b2,c2; + cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; + if ( a1 > b1 ) + swap(a1, b1); + if ( a1 > c1 ) + swap(a1, c1); + if ( b1 > c1 ) + swap(b1, c1); + if ( a2 > b2 ) + swap(a2, b2); + if ( a2 > c2 ) + swap(a2, c2); + if ( b2 > c2 ) + swap(b2, c2); + + if ((a1 == a2) && (b1 == b2) && (c1 == c2)) cout << "Boxes are equal"; + else if ((a1 <= a2) && (b1 <= b2) && (c1 <= c2)) + cout <<"The first box is smaller than the second one"; + else if ((a1 >= a2) && (b1 >= b2) && (c1 >= c2)) + cout <<"The first box is larger than the second one"; + else cout <<"Boxes are incomparable"; +}; From fda436a169ad4418cc35badd5cf226404f15f9d7 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 25 Sep 2019 17:36:58 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8,=20?= =?UTF-8?q?=D1=86=D0=B8=D0=BA=D0=BB=D1=8B=20=D0=B8=20=D0=BC=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B2=D1=8B.....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/cpp/t01_max3.cpp | 18 ++++-------- src/main/cpp/t02_triangle.cpp | 18 ++++-------- src/main/cpp/t03_equal3.cpp | 24 ++++------------ src/main/cpp/t10_sort3.cpp | 28 ++++++------------ src/main/cpp/t11_boxes.cpp | 54 ++++++++++++++++++++++++----------- 5 files changed, 64 insertions(+), 78 deletions(-) diff --git a/src/main/cpp/t01_max3.cpp b/src/main/cpp/t01_max3.cpp index 398f2104..2e8fe868 100644 --- a/src/main/cpp/t01_max3.cpp +++ b/src/main/cpp/t01_max3.cpp @@ -16,17 +16,11 @@ #include using namespace std; -int sorted(int *array, int size){ - int max = *array; - for (int i = 0; i < size; ++i) { - if (*(array + i) > max) - max = *(array + i); - else continue; - } - return max; -} + int t01_max3() { - int a[3]; - cin >> a[0] >> a[1] >> a[2]; - cout << sorted(a,3); + int a,b,c; + cin >> a >> b >> c; + if (a>=b && a>=c) {cout << a;} + else if (b>=a && b>=c) cout << b; + else if (c>=a && c>=b) cout << c; }; diff --git a/src/main/cpp/t02_triangle.cpp b/src/main/cpp/t02_triangle.cpp index 18f74af3..68eca80e 100644 --- a/src/main/cpp/t02_triangle.cpp +++ b/src/main/cpp/t02_triangle.cpp @@ -17,17 +17,11 @@ #include using namespace std; -bool check(int a, int b, int c){ - if (c < (a + b)) - return true; - else - return false; - -} + int t02_triangle() { - int a, b, c; - cin >> a >> b >> c; - if (check(a,b,c) && check(a,c,b) && check(b,c,a)) - cout << "YES"; - else cout << "NO"; + int A,B,C; + cin>>A>>B>>C; + if (A<(B+C) && B<(A+C) && C<(A+B)) + cout<<"YES"; + else cout<<"NO"; }; diff --git a/src/main/cpp/t03_equal3.cpp b/src/main/cpp/t03_equal3.cpp index dc33c18f..0b4abed4 100644 --- a/src/main/cpp/t03_equal3.cpp +++ b/src/main/cpp/t03_equal3.cpp @@ -17,23 +17,11 @@ #include using namespace std; -int check(int *array, int start = 0, int size = 3){ - int count = 0; - for (int i = start; i < size; ++i) - if (*(array + start) == *(array + i)) - count++; - return count; -} + int t03_equal3() { - int a[3]; - cin >> a[0] >> a[1] >> a[2]; - if (check(a) == 3) - cout << 3; - else if (check(a) == 2) - cout << 2; - else { - if (check(a,1) == 2) - cout << 2; - else cout << 1; - } + int a,b,c; + cin>>a>>b>>c; + if (a==b && a==c && b==c) {cout<<3;} else + if (a==b || a==c || b==c) {cout<<2;} else + {cout<<0;} }; diff --git a/src/main/cpp/t10_sort3.cpp b/src/main/cpp/t10_sort3.cpp index 419876bc..c7c8a3cb 100644 --- a/src/main/cpp/t10_sort3.cpp +++ b/src/main/cpp/t10_sort3.cpp @@ -17,24 +17,14 @@ #include using namespace std; -void swap(int &a, int &b){ - a = a^b; - b = a^b; - a = a^b; -} -void sort(int *array, int size = 3){ - for (int i = 0; i < size; ++i) { - if (*(array + i) > *(array + i+1)) - swap(*(array + i), *(array + i+1)); - } -} + int t10_sort3() { - int a[3]; - for (int i = 0; i < 3; ++i) { - cin >> a[i]; - } - sort(a); - for (int i = 0; i < 3; ++i) { - cout << a[i] << ' '; - } + int a,b,c; + cin>>a>>b>>c; + if (a>=b && a>=c && b>=c) cout<=b && a>=c && b<=c) cout<=a && b>=c && a>=c) cout<=a && b>=c && a<=c) cout<=b && c>=a && b>=a) cout<=b && a<=c && b<=a) cout< using namespace std; -void swap(int &a, int &b){ - a = a^b; - b = a^b; - a = a^b; -} + int t11_boxes() { int a1,b1,c1,a2,b2,c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; - if ( a1 > b1 ) - swap(a1, b1); - if ( a1 > c1 ) - swap(a1, c1); - if ( b1 > c1 ) - swap(b1, c1); - if ( a2 > b2 ) - swap(a2, b2); - if ( a2 > c2 ) - swap(a2, c2); - if ( b2 > c2 ) - swap(b2, c2); + if ( a1 > b1 ) { + int temp; + temp = a1; + a1 = b1; + b1 = temp; + } + if ( a1 > c1 ) { + int temp; + temp = a1; + a1 = c1; + c1 = temp; + } + if ( b1 > c1 ) { + int temp; + temp = b1; + b1 = c1; + c1 = temp; + } + if ( a2 > b2 ) { + int temp; + temp = a2; + a2 = b2; + b2 = temp; + } + if ( a2 > c2 ) { + int temp; + temp = a2; + a2 = c2; + c2 = temp; + } + if ( b2 > c2 ) { + int temp; + temp = b2; + b2 = c2; + c2 = temp; + } if ((a1 == a2) && (b1 == b2) && (c1 == c2)) cout << "Boxes are equal"; else if ((a1 <= a2) && (b1 <= b2) && (c1 <= c2))