Арбуз
C++
#include <iostream>
#include <string>
using std::cin;
using std::cout;
int main()
{
int n;
cin >> n;
if(n == 2 || n % 2 == 1)
{
cout << "NO\n";
}
else
{
cout << "YES\n";
}
return 0;
}
Python
w = int(input())
can = w % 2 == 0 and w > 2
print('YES' if can else 'NO')
Слишком длинные слова
C++
#include <iostream>
#include <string>
using std::cin;
using std::cout;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; ++t)
{
std::string str;
cin >> str;
if(str.size() > 10)
{
cout << str[0] << str.size() - 2 << str.back() << "\n";
}
else
{
cout << str << "\n";
}
}
return 0;
}
Python
t = int(input())
for _ in range(t):
word = input()
if len(word) > 10:
res = f'{word[0]}{len(word) - 2}{word[-1]}'
else:
res = word
print(res)
Красивая матрица
C++
#include <iostream>
#include <string>
using std::cin;
using std::cout;
int main()
{
int row, col;
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
{
int x;
cin >> x;
if (x == 1)
{
row = i;
col = j;
}
}
}
cout << std::abs(2 - row) + std::abs(2 - col) << "\n";
return 0;
}
Python
n, m = 5, 5
x, y = -1, -1
for i in range(n):
values = input().split()
for j in range(m):
if values[j] == '1':
x, y = i, j
ans = abs(n // 2 - x) + abs(m // 2 - y)
print(ans)
О трате времени
C++
#include <bits/stdc++.h>
using std::cin;
using std::cout;
int main()
{
using real = long double;
real ans = 0.;
int n, k;
cin >> n >> k;
int prev_x, prev_y;
cin >> prev_x >> prev_y;
for (int i = 1; i < n; ++i)
{
int x, y;
cin >> x >> y;
real dx = x - prev_x;
real dy = y - prev_y;
real len = std::sqrt(dx * dx + dy * dy);
ans += len;
prev_x = x;
prev_y = y;
}
ans /= 50;
ans *= k;
cout << ans << "\n";
system("pause");
return 0;
}
Python
import math
def read_ints():
return map(int, input().split())
n, k = read_ints()
points = [
tuple(read_ints())
for _ in range(n)
]
def distance(p1, p2):
x1, y1 = p1
x2, y2 = p2
dx = x2 - x1
dy = y2 - y1
return math.sqrt(dx * dx + dy * dy)
total = 0
for i in range(1, n):
total += distance(points[i - 1], points[i])
total *= k
speed = 50
total /= speed
print(f'{total:.10f}')
Восстановление трех чисел
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
int main()
{
std::vector<int> vec(4);
for (int i = 0; i < 4; ++i) cin >> vec[i];
std::sort(vec.begin(), vec.end());
for (int i = 0; i < 3; ++i) cout << vec.back() - vec[i] << " ";
return 0;
}
Python
def read_ints():
return map(int, input().split())
x = list(read_ints())
x.sort()
ans = [
x[-1] - value
for value in x[:-1]
]
print(*ans)
Duff и мясо
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
int main()
{
int n;
cin >> n;
int ans = 0;
int min_price = 1000000000;
for (int i = 0; i < n; ++i)
{
int need, price;
cin >> need >> price;
if (price < min_price)
{
min_price = price;
}
ans += need * min_price;
}
cout << ans << "\n";
return 0;
}
Python
def read_ints():
return map(int, input().split())
n = int(input())
ans = 0
best_price = 101
for _ in range(n):
need, price = read_ints()
best_price = min(best_price, price)
ans += need * best_price
print(ans)
Не NP
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
int main()
{
int l, r;
cin >> l >> r;
if (l == r) cout << l << "\n";
else cout << 2 << "\n";
system("pause");
return 0;
}
Python
def read_ints():
return map(int, input().split())
left, right = read_ints()
ans = left if left == right else 2
print(ans)
Подсчёт функции
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
int main()
{
long long n;
cin >> n;
long long ans = n / 2;
if(n % 2 == 1) ans -= n;
cout << ans << "\n";
system("pause");
return 0;
}
Python
n = int(input())
ans = n // 2
if n % 2 == 1:
ans -= n
print(ans)




