Tin học

No_pvp
Xem chi tiết
Gia Huy
8 tháng 7 2023 lúc 15:26

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int ai[n];
    for (int i = 0; i < n; i++) {
        cin >> ai[i];
    }

    vector<int> pairs(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (ai[i] + ai[j] == k) {
                pairs.push_back(make_pair(i, j));
            }
        }
    }

    sort(pairs.begin(), pairs.end());
    int count = 0;
    pairs.erase(pairs.begin(), pairs.end());
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (pairs[i].first == i && pairs[i].second == j) {
                count++;
                break;
            }
        }
        if (count == n) {
            break;
        }
        if (pairs[i].second == j) {
            while (pairs[i].first != i) {
                i++;
                count++;
                pairs.erase(pairs.begin() + i);
                for (int j = 0; j < n; j++) {
                    if (ai[j] + ai[i] == k) {
                        pairs.push_back(make_pair(j, i+1));
                        break;
                    }
                }
                for (int j = 1;; j++) {
                    int count_n = 0, count_s = 0;
                    for (int i = j-1; i >= 0; i--) {
                        if (pairs[i].second == j) {
                            j++;
                            count_n++;
                            pairs.erase(pairs.begin() + i + 1);
                            pairs.er

Bình luận (1)
No_pvp
Xem chi tiết
Gia Huy
8 tháng 7 2023 lúc 15:27

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

#include <bits/stdc++.h>

int main() {
    int n;
    cin>>n;
    int sum=0;

    for(int i=1;i<=n;i++)
    {
        sum+=i*i;
    }
    cout<<"The total is: "<<sum<<endl;

    for(int j=0;j<=50000;j++)
    {
        int du=j%10;
        int tongcacso=j%10*j%10*j%10;
        cout<<"du="<<du<<endl;
        sum=sum+du*du*du;
        cout<<"\nsum= "<<sum<<endl;
        cout<<"sum= (sum+j*j*j) "<<endl;
    }

    return 0;
}

 

Bình luận (0)
nguyenthuha2904
Xem chi tiết
Gia Huy
8 tháng 7 2023 lúc 15:35

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
using namespace std;

#include <bits/stdc++.h>

int main() {
    int n;
    cin >> n;
    int total = 0;

    for (int i = 1; i <= n; i++) {
        if (i % 20 == 0 && i % 10 != 0) {
            if (i <= (n / 10)) {
                total += i * i;
            }
        } else {
            total += i;
        }
    }
    cout << "The total is: " << total << endl;

    for (int i = 0; i < n; i++) {
        int du = i % 10;
        int tongcacso = i % 10 * i % 10 * i % 10;
        cout << "du = " << du << endl;
        total += du * du * du;
        cout << "\nsum = " << total << endl;
        cout << "sum = (sum+i*i*i) " << endl;
    }

    return 0;
}

Bình luận (0)
Phía sau một cô gái
7 tháng 7 2023 lúc 20:40

program bai_toan;

var

      n, chuc, donvi: integer;

begin

      write('Nhap so nguyen duong 2 chu so n: ');

      readln(n);

      chuc := n div 10;

      donvi := n mod 10;

      if (chuc mod 2 = 0) and (donvi mod 2 = 0) then

            writeln('Khong co chu so le')

      else

      begin

            if chuc mod 2 <> 0 then

                  writeln('Chu so le cua n o hang chuc la: ', chuc);

            if donvi mod 2 <> 0 then

                  writeln('Chu so le cua n o hang don vi la: ', donvi);

      end;

      readln;

end.

Bình luận (0)
Trí Nguyễn
Xem chi tiết
Phía sau một cô gái
7 tháng 7 2023 lúc 20:19

program bai_toan;

var

      N, i, sum: integer;

begin

      write('Nhap so N: ');

      readln(N);

      write('Cac uoc cua ', N, ' khong ke ', N, ' la: ');

      for i := 1 to N - 1 do

            if N mod i = 0 then

                  write(i, ' ');

      writeln;

      sum := 0;

      for i := 1 to N - 1 do

      begin

            if N mod i = 0 then sum := sum + i;

      end;

      if sum = N then writeln(N, ' la so hoan hao')

      else writeln(N, ' khong phai la so hoan hao');

      writeln;

      writeln('Tat ca so hoan hao trong pham vi 1 -> ', N, ' la:');

      for i := 1 to N do

      begin

            sum := 0;

            for j := 1 to i - 1 do

            begin

                  if i mod j = 0 then sum := sum + j;

            end;

            if sum = i then writeln(i);

      end;

      readln;

end.

Bình luận (0)
No_pvp
Xem chi tiết
Phía sau một cô gái
7 tháng 7 2023 lúc 20:13

#include<bits/stdc++.h>

using namespace std;

     int main() {

     int N;

     cin >> N;

     int sum = 0;

     for (int i = 1; i <= N; i++) {

          if (sqrt(i) == (int)sqrt(i)) {

               sum += i;

          }

     }

     cout << sum << endl;

     return 0;

}

Bình luận (0)
Long ca ca
Xem chi tiết
Phía sau một cô gái
7 tháng 7 2023 lúc 20:56

program bai_toan;

var

      S, S1: string;

      i, j, n: integer;

begin

      write('Nhap xau S: ');

      readln(S);

      n := length(S);

      for i := n downto 1 do

      begin

            S1 := S1 + S[i];

      end;

      for i := n downto 1 do

      begin

            if S = S1 then break;

            S := S + S1[i];

      end;

      writeln('Xau doi xung ngan nhat la: ', S);

      readln;

end.

Bình luận (0)
HIẾU MẶT MOI
Xem chi tiết
Phía sau một cô gái
5 tháng 7 2023 lúc 20:43

program dem_so_doi_xung;

var

     n, i, j, count: longint;

     s: string;

function doi_xung(s: string): boolean;

var

     i: longint;

begin

     for i := 1 to length(s) div 2 do

          if s[i] <> s[length(s) - i + 1] then

          begin

               doi_xung := false;

               exit;

          end;

     doi_xung := true;

end;

function doi_xung_dang_non(s: string): boolean;

var

     i: longint;

begin

     for i := 1 to length(s) div 2 do

          if not((s[i] = '1') or (s[i] = '0') or (s[i] = '8')) or (s[length(s) - i + 1] <> s[i]) then

          begin

               doi_xung_dang_non := false;

               exit;

          end;

     doi_xung_dang_non := true;

end;

begin

     write('Nhap n: ');

     readln(n);

     count := 0;

     for i := 1 to n do

     begin

          str(i, s);

          if doi_xung(s) and doi_xung_dang_non(s) then

               inc(count);

     end;

     writeln('So luong so doi xung dang non la: ', count);

     readln;

end.

Bình luận (0)
Long ca ca
Xem chi tiết
Khoa Dao Dang
Xem chi tiết
Phía sau một cô gái
3 tháng 7 2023 lúc 22:48

#include<bits/stdc++.h>

using namespace std;

int main() {

      int n;

      cin >> n;

      int mid = (n+1)/2;

      int left = 1, right = n;

      for(int i=1; i<=n; i++) {

            if(i%2!=0) {

                  cout << left << " ";

                  left++;

            }

            else {

                  cout << right << " ";

                  right--;

            }

      }

      cout << endl;

      return 0;

}

Bình luận (0)
Khoa Dao Dang
3 tháng 7 2023 lúc 22:35

làm giúp em bằng c++ hoặc c cũng được ạ

Bình luận (0)
Nguyễn Hoàng Duy
4 tháng 7 2023 lúc 16:37

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << n / 2 << endl;
    return 0;
}

Bình luận (0)