O'lchov birliklari :: Yechimlar
Masala A
Kiritilgan uzunlik o’lchov birligini metr o’lchov birligiga o’tkazadigan dastur tuzing.
Bitta qatorda uzunlik qiymati (1 dan 2000 gacha) va uning turi
Metrdagi natija
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <itboom.h>
int main() {
char typ[3] = {0};
int v;
scanf("%d %s", &v, &typ);
if (strcmp(typ, "m") == 0) {
printf("%d m", v);
} else if (strcmp(typ, "km") == 0) {
printf("%d m", v * 1000);
} else if (strcmp(typ, "sm") == 0) {
printf("%g m", v / 100.0);
} else {
printf("%g m", v / 1000.0);
}
return 0;
}
import math
import itboom
def main():
v, typ = input().split()
v = int(v)
if typ == "m":
print(v, "m")
elif typ == "km":
print(v * 1000, "m")
elif typ == "sm":
print(f"{v / 100:g}", "m")
else:
print(f"{v / 1000:g}", "m")
if __name__ == '__main__':
main()
Masala B
Kiritilgan uzunlik o’lchov birligini kg o’lchov birligiga o’tkazadigan dastur tuzing.
Bitta qatorda uzunlik qiymati (1 dan 2000 gacha) va uning turi
KGdagi natija
#include <stdio.h>
int main() {
char typ[3] = {0};
int v;
scanf("%d %s", &v, &typ);
if (strcmp(typ, "kg") == 0) {
printf("%d kg", v);
} else if (strcmp(typ, "t") == 0) {
printf("%d kg", v * 1000);
} else if (strcmp(typ, "s") == 0) {
printf("%d kg", v * 100);
} else {
printf("%g kg", v / 1000.0);
}
return 0;
}
import math
import itboom
def main():
v, typ = input().split()
v = int(v)
if typ == "kg":
print(v, "kg")
elif typ == "t":
print(v * 1000, "kg")
elif typ == "s":
print(v * 100, "kg")
else:
print(f"{v / 1000:g}", "kg")
if __name__ == '__main__':
main()
Masala C
Kiritilgan hh:mm:ss ko’rinishidagi vaqtni sekundda ifodalaydigan dastur tuzing.
hh:mm:ss ko’rinishidagi vaqt
Kiritilgan vaqtning sekunddagi qiymati
#include <stdio.h>
int main() {
int h, m, s;
scanf("%d:%d:%d", &h, &m, &s);
printf("%d", 3600 * h + 60 * m + s);
return 0;
}
import math
import itboom
def main():
h, m, s = map(int, input().split(":"))
print(3600 * h + 60 * m + s)
if __name__ == '__main__':
main()
Masala D
Kiritilgan km/soat tezlikni m/s qiymatga o’tkazadigan dastur tuzing.
1 dan 2000 gacha orqalidagi km/soat tezlik qiymati
m/s dagi qiymat (3 xona aniqlikda)
#include <stdio.h>
int main() {
int v;
scanf("%d", &v);
printf("%.3f m/s", v / 3.6f);
return 0;
}
def main():
vv = input().split()
v = int(vv[0])
print(f"{v / 3.6:.3f} m/s")
if __name__ == '__main__':
main()
Masala E
Kiritilgan 0,1,2,3,4 sonlarini 2 ga ko’paytiradigan dastur tuzing.
0, 1, 2, 3 va 4 sonlari
Kiritilgan sonning 2 ka ko’paytirilgan natijasi
,>++++++++[<------>-]#<[>++<-]#++++++++#[>++++++<-]#>.