Необис / Java
.docx1) https://www.solveway.club/algo/problem/205
Сумма нечетных позиций import java.util.Scanner;
public class Solution
{
public static void main (String[] argv)
{
Scanner sc = new Scanner(System.in);
int i, s1=0, s2=0, k=0, n, n1, n2;
n = sc.nextInt();
n1 = n;
while(n1 != 0)
{
n2 = n1; n1/=10; n2%=10;
if(k % 2 == 0) s1+=n2;
else s2+=n2;
k++;
}
if(k % 2 == 0)
System.out.println(s2);
else
System.out.println(s1);
}
}
2) https://www.solveway.club/algo/problem/188 Черно-белый рисунок
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
suma = 0
NM = []
for i in range(N):
for j in range(N):
NM.append(A[i][j])
suma += A[i][j]
LNM = len(NM)
x = suma//LNM
for i in range(N):
for j in range(N):
if A[i][j] < x:
A[i][j] = 0
else:
A[i][j] = 255
for i in range(len(A)):
for j in range(len(A[i])):
if j > 0:
print(end=' ')
print(A[i][j], end='')
print()
3) https://www.solveway.club/algo/problem/256
Результаты олимпиады
import java.util.Scanner;
public class Solution {
int i;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a = new int[10000];
int[] b = new int[10000];
int q;
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
for (int j = 0; j < n - 1; j++)
for (int i = 0; i < n - 1; i++)
if (b[i] < b[i + 1] || b[i] == b[i + 1] && a[i] > a[i + 1]) {
q = a[i];
a[i] = a[i + 1];
a[i + 1] = q;
q = b[i];
b[i] = b[i + 1];
b[i + 1] = q;
}
for (int i = 0; i < n; i++)
System.out.println(a[i] + " " + b[i]);
}
} 4) https://www.solveway.club/algo/problem/255
Вставка числа в массив
import java.util.Scanner;
public class Solution {
public static void main(String[] argv) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[1001];
int n;
n = sc.nextInt();
for (int i = 0; i < n; ++i) {
arr[i] = sc.nextInt();
}
int number_to_insert = sc.nextInt();
int pos_to_insert = sc.nextInt();
for (int i = n; i >= pos_to_insert; --i) {
arr[i] = arr[i - 1];
}
arr[pos_to_insert - 1] = number_to_insert;
++n;
for (int i = 0; i < n; ++i) {
System.out.println(arr[i]);
}
System.out.println();
}
}
5) https://www.solveway.club/algo/problem/250
Ближайшее число
N = int(input())
lst = map(int, (input().split()))
x = int(input())
print(min(lst, key=lambda a:abs(a-x)))
6) https://www.solveway.club/algo/problem/236
Танцующее предложение
7) https://www.solveway.club/algo/problem/235
Правильный пароль
import java.util.Scanner;
public class Solution
{
public static void main (String[] argv)
{
Scanner sc = new Scanner(System.in);
int pass = 0;
do {
pass = sc.nextInt();
if(pass != 2016) {
System.out.println("Incorrect password");
}
}
while(pass != 2016);
System.out.println("Access permitted");
}
}
8) https://www.solveway.club/algo/problem/233
Интервал
N = int(input())
X = [int(input())for i in range(N)]
a = []
b = []
c = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
for i in X:
if i > -107 and i < 107:
if i in c:
a.append(i)
else:
b.append(i)
print(f'{len(a)} in')
print(f'{len(b)} out')
9) https://www.solveway.club/algo/problem/231
LED
10) https://www.solveway.club/algo/problem/229
Фибоначчи массив
from math import sqrt
N = int(input())
M = [int(input()) for i in range(N)]
for i in M:
f = int(((1+sqrt(5))**i-(1-sqrt(5))**i)/(2**i*sqrt(5)))
print(f'Fib({i}) = {f}')
11) https://www.solveway.club/algo/problem/228
Замена в массиве
N = 10
if N > -100000 and N < 100000:
array = [int(input()) for i in range(N)]
for i in range(len(array)):
if array[i] == 0 or array[i] < 0:
array[i] = 1
for i in range(len(array)):
print(f'N{[i]} = {array[i]}')
12) https://www.solveway.club/algo/problem/227
Самое большое число и его позиция
N = 100
M = [abs(int(input())) for item in range(N)]
print(max(M))
print(M.index(max(M)) + 1)
13) https://www.solveway.club/algo/problem/122
Сумма восьмеричных
def f(x):
i = 0
ten = 0
while x > 0:
ten += (8**i)*(x%10)
x //= 10
i += 1
return ten
def v(x):
two = ''
while x > 0:
y = x%8
two = str(y)+two
x //= 8
return two
a, b = map(int, input().split())
pr = f(a)+f(b)
print(v(pr))
14) https://www.solveway.club/algo/problem/100
Арифметическая последовательность
Выполнено: 11/14 задач