Регистрация
Войти
Стать экспертом Правила
Информатика

Пожалуйста посчитайте НАПИСАТЬ КОДЫ НА С++ ОЧЕНЬ СРОЧНО НУЖНО

ОТВЕТЫ
  • #include <fstream>
  • #include <cmath>
  • void first_task(std::ifstream &cin, std::ofstream &cout) {
  •    int n, k = 1; cin >> n >> k;
  •    cout << n / k;
  • }
  • void second_task(std::ifstream &cin, std::ofstream &cout) {
  •    int N; cin >> N;
  •    cout << 2 * (N / 2 + 1);
  • }
  • void third_task(std::ifstream &cin, std::ofstream &cout) {
  •    int N; cin >> N;
  •    auto t = [](int c, int N){return c / (int) pow(10, N) % 10;};
  •    cout << t(N, 2) + t(N, 1) + t(N, 0);
  • }
  • void fourth_task(std::ifstream &cin, std::ofstream &cout) {
  •    int N; cin >> N;
  •    for (int it = 0; it < log2(N); ++it) {
  •        cout << pow(2, it) << " ";
  •    }
  • }
  • void fifth_task(std::ifstream &cin, std::ofstream &cout) {
  •    int h, a, b;
  •    cin >> h >> a >> b;
  •    int h0 = h - a, dx = a - b;
  •    int g = 1 + h0/dx + (h0%dx + dx - 1)/dx;
  •    if (g < 0)
  •        cout << INFINITY;
  •    else
  •        cout << g;
  • }
  • int main() {
  •    std::ifstream cin("input.txt");
  •    std::ofstream cout("output.txt");
  •    // Choose your function
  •    int N = 0; // 0-4
  •    void (*tasks[5]) (std::ifstream &, std::ofstream &) = {first_task, second_task, third_task, fourth_task, fifth_task};
  •    tasks[N](cin, cout);
  •    return 0;
  • }
635
Контакты
Реклама на сайте
Спрошу
О проекте
Новым пользователям
Новым экспертам