Lập trình đơn giản

No_pvp
Xem chi tiết
Nguyễn Hà Bảo Lâm
16 tháng 7 2023 lúc 21:16

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
const int maxN = 1e4 + 1;
int n, k, arr[maxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
cout << arr[k - 1]; 
}


Input:
7 4
29 847 1928 45 298 918219 38129

Output: 847

Bình luận (1)
No_pvp
Xem chi tiết
No_pvp
Xem chi tiết
Nguyễn Hoàng Duy
13 tháng 7 2023 lúc 17:55

#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    for (int i = 1; i <= 3; i++)
    {
        cin >> s;
        cout << s << " ";
    }
}

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

#include <iostream>

using namespace std;

int main() {

       string A, B;

       getline(cin, A);

       getline(cin, B);

       int count = 0;

       for (int i = 0; i <= B.length() - A.length(); i++) {

              bool found = true;

              for (int j = 0; j < A.length(); j++) {

                     if (B[i+j] != A[j]) {

                            found = false;

                            break;

                     }

              }

              if (found) {

                     count++;

              }

       }

       cout << count;

       return 0;

}

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

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

int main() {
    int T, n;
    cin>>T;
    for(int t=0;t<T;t++){
        int n,k,a,i;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int ans=0;
        int c=0;
        int sum=0;
        int c0=0;
        int c1=0;
        int c2=0;
        for(int i=0;i<n;i++){
            sum+=a[i];
        }
        for(int i=0;i<n;i++){
            if(sum<k && i!=0){
                sum+=a[i]-1;
            }
        }
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                int sum=0;
                for(int l=i;l<j;l++){
                    sum+=a[l];
                }
                if(sum==k){
                    c0=i;
                    c1=j;
                }
            }
        }
        printf("Case %d : %d - %d (c0,c1)\n",t+1,c*n+c0,c*n+c1);
        ++c;
    }
    return 0;
}

Bình luận (1)
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)
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)