378 lines
11 KiB
XML
378 lines
11 KiB
XML
<?xml version='1.0' ?>
|
|
<Pandoc api-version="1,23,1,2">
|
|
<meta />
|
|
<blocks>
|
|
<Header id="задач-по-теме-целые-числа-на-java" level="1">10 задач по теме «Целые числа» на Java</Header>
|
|
<Para>Все решения используют только арифметические операторы (<Code>+</Code>, <Code>-</Code>, <Code>*</Code>, <Code>/</Code>, <Code>%</Code>) и стандартный ввод/вывод. Без <Code>if</Code>, <Code>for</Code>, <Code>while</Code>, <Code>switch</Code> и без создания собственных функций.</Para>
|
|
<HorizontalRule />
|
|
<Header id="задача-1.-сумма-и-произведение-цифр-двузначного-числа" level="2">Задача 1. Сумма и произведение цифр двузначного числа</Header>
|
|
<Para><Strong>Условие:</Strong> Дано двузначное число. Найти сумму и произведение его цифр.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>47</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>11 28</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task1 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int a = n / 10;
|
|
int b = n % 10;
|
|
System.out.println(a + b);
|
|
System.out.println(a * b);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-2.-число-обратное-двузначному" level="2">Задача 2. Число, обратное двузначному</Header>
|
|
<Para><Strong>Условие:</Strong> Дано двузначное число. Получить число, записанное теми же цифрами в обратном порядке.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>47</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>74</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task2 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int result = (n % 10) * 10 + (n / 10);
|
|
System.out.println(result);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-3.-сумма-цифр-трёхзначного-числа" level="2">Задача 3. Сумма цифр трёхзначного числа</Header>
|
|
<Para><Strong>Условие:</Strong> Дано трёхзначное число. Найти сумму его цифр.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>385</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>16</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task3 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int sum = n / 100 + (n / 10) % 10 + n % 10;
|
|
System.out.println(sum);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-4.-перевод-секунд-в-часы-минуты-и-секунды" level="2">Задача 4. Перевод секунд в часы, минуты и секунды</Header>
|
|
<Para><Strong>Условие:</Strong> Дано целое число секунд <Code>t</Code>. Перевести в часы, минуты и секунды.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>7265</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>2 1 5</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task4 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int t = sc.nextInt();
|
|
int h = t / 3600;
|
|
int m = (t % 3600) / 60;
|
|
int s = t % 60;
|
|
System.out.println(h);
|
|
System.out.println(m);
|
|
System.out.println(s);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-5.-последняя-цифра-числа-в-степени" level="2">Задача 5. Последняя цифра числа в степени</Header>
|
|
<Para><Strong>Условие:</Strong> Дано число <Code>n</Code>. Найти последнюю цифру числа <Code>n²</Code>.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>37</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault" />
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task5 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int last = n % 10;
|
|
System.out.println((last * last * last * last) % 10);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-7.-обмен-цифр-трёхзначного-числа-циклический-сдвиг" level="2">Задача 7. Обмен цифр трёхзначного числа (циклический сдвиг)</Header>
|
|
<Para><Strong>Условие:</Strong> Дано трёхзначное число <Code>abc</Code>. Получить число <Code>bca</Code> (первую цифру в конец).</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>385</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>853</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task7 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int a = n / 100;
|
|
int b = (n / 10) % 10;
|
|
int c = n % 10;
|
|
int result = b * 100 + c * 10 + a;
|
|
System.out.println(result);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-8.-сумма-цифр-четырёхзначного-числа" level="2">Задача 8. Сумма цифр четырёхзначного числа</Header>
|
|
<Para><Strong>Условие:</Strong> Дано четырёхзначное число. Найти сумму его цифр.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>1234</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>10</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task8 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int n = sc.nextInt();
|
|
int sum = n / 1000 + (n / 100) % 10 + (n / 10) % 10 + n % 10;
|
|
System.out.println(sum);
|
|
}
|
|
}</CodeBlock>
|
|
<HorizontalRule />
|
|
<Header id="задача-9.-количество-полных-минут-в-сутках" level="2">Задача 9. Количество полных минут в сутках</Header>
|
|
<Para><Strong>Условие:</Strong> Дано число минут <Code>m</Code>. Найти количество полных суток и остаток минут.</Para>
|
|
<Table>
|
|
<Caption />
|
|
<colspecs>
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
<ColSpec alignment="AlignDefault" col-width="0" />
|
|
</colspecs>
|
|
<TableHead>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Ввод:</Strong></Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain><Strong>Вывод:</Strong></Plain>
|
|
</Cell>
|
|
</Row>
|
|
</TableHead>
|
|
<TableBody row-head-columns="0">
|
|
<header />
|
|
<body>
|
|
<Row>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>5000</Plain>
|
|
</Cell>
|
|
<Cell alignment="AlignDefault">
|
|
<Plain>3 680</Plain>
|
|
</Cell>
|
|
</Row>
|
|
</body>
|
|
</TableBody>
|
|
<TableFoot />
|
|
</Table>
|
|
<Para><Strong>Решение:</Strong></Para>
|
|
<CodeBlock class="java">import java.util.Scanner;
|
|
|
|
public class Task9 {
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int m = sc.nextInt();
|
|
int days = m / 1440;
|
|
int rest = m % 1440;
|
|
System.out.println(days);
|
|
System.out.println(rest);
|
|
}
|
|
}</CodeBlock>
|
|
</blocks>
|
|
</Pandoc>
|