Harfli ifodalar II :: Yechimlar
Masala A
Kiritilgan x
va y
larning qiymatidan kelib chiqib z
ning qiymatini hisoblab, yuzdan bir xona aniqlikda, ekranga chiqaradigan dastur tuzing.
$$ z = sin(x) + \frac{cos(y^2)}{x + y} - \pi * y $$
Bitta qatorda x
va y
ning qiymatlari (-1000 dan 1000 gacha)
Yuzdan bir xona aniqlikdagi z
ning qiymati
#include <stdio.h>
#include <math.h>
int main() {
int x, y;
scanf("%d %d", &x, &y);
float z = sin(x) + cos(y * y) / (x + y) - 3.14f * y;
printf("%.02f", z);
return 0;
}
import math
def main():
x, y = map(int, input().split())
z = math.sin(x) + math.cos(y * y) / (x + y) - 3.14 * y
print(round(z, 2))
if __name__ == '__main__':
main()
Masala B
Kiritilgan x
qiymat musbat bo’lsa A
formula qiymatini, aks holda B
formula qiymatini mingdan bir xona aniqlikda ekranga chiqaradigan dastur tuzing.
$$ A = \sqrt{\frac{x ^ 3}{x - 2}} * x^{-1} $$
$$ B = \sqrt[3]{x^2} + 5x $$
x
ning qiymati -1000 dan 1000 gacha.
Masala shartidagi formula qiymati
#include <stdio.h>
#include <math.h>
int main() {
int x;
scanf("%d", &x);
float A = sqrt((float)x * x * x / (x - 2)) / x;
float B = cbrt(x * x) + 5 * x;
if (x > 0) {
printf("%.8g", round(A * 1000.0) / 1000.0);
} else {
printf("%.8g", round(B * 1000.0) / 1000.0);
}
return 0;
}
import math
import itboom
def main():
x = int(input())
A = math.sqrt(x * x * x / (x - 2)) / x
B = math.cbrt(x * x) + 5 * x
if x > 0:
print(round(A, 3))
else:
print(round(B, 3))
if __name__ == '__main__':
main()
Masala C
Kiritilgan a
va b
qiymatlar uchun quyidagi y
formulaning eng kichik qiymatini aniqlaydigan dastur tuzing.
$$ y = \frac{x * a - b}{x * b - a} $$
Bitta qatorda a
va b
larning qiymat -1000 dan 1000 gacha.
y
ning eng kichik qiymati mingdan bir xona aniqlikda.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <itboom.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
float my = INFINITY;
for(int x = -1000; x <= 1000; x++) {
float y = (x * a - b) / (float)(x * b - a);
if (y < my) {
my = y;
}
}
printf("%.8g", round(my * 1000.0) / 1000.0);
return 0;
}
import math
import itboom
def main():
a, b = map(int, input().split())
my = float('inf')
for x in range(-1000, 1001):
y = (x * a - b) / (x * b - a)
my = min(y, my)
print(format(round(my, 3), "g"))
if __name__ == '__main__':
main()
Masala D
Python dasturlash tilida uning imkoniyatlaridan foydalanib yozilgan. Agar kod juda qisqa yoki tushunarsiz bo’lsa, C dasturlash tilidagi algoritmdan foydalansangiz bo’ladi.
Kiritilgan birhadning koeffitsiyenti hisoblaydigan dastur tuzing.
Birinchi qatorda jami belgilar soni (manfiy son 2 ta belgidan iborat)
Ikkinchi qatorda musbat, manfiy hamda lotin harflaridan iborat (daraja qatnashmagan) bir had
Kiritilgan birhadning koeffitsiyenti qiymati
#include <stdio.h>
#include <math.h>
int main() {
int n;
int v = 1;
int k = 0;
scanf("%d\n", &n);
for(int i = 0; i < n; i++) {
char c;
scanf("%c", &c);
if (c == '-') {
v = -v;
} else if (isdigit(c)) {
k *= 10;
k += c - '0';
} else if (k > 0) {
v *= k;
k = 0;
}
}
if (k > 0) {
v *= k;
}
printf("%d\n", v);
return 0;
}
import string
import functools
import operator
def main():
n = int(input())
s = input()
for letter in string.ascii_lowercase:
s = s.replace(letter, " ")
print(functools.reduce(operator.mul, map(lambda s: -1 if s == '-' else int(s), s.split()), 1))
if __name__ == '__main__':
main()
Masala E
Kiritilgan qiymatni ekranga chiqaradigan dastur tuzing (echo dastur)
Har xil uzunlikdagi matn
Kiritilgan qiymatning o’zi
,[.,]