eolymp
bolt
Try our new interface for solving problems
dərc olunub 08.01.24 21:59:34
#include <bits/stdc++.h> //including necessary libraries
using namespace std; //using std
int main(){ //main code function start
    ios_base::sync_with_stdio(false); //speeding up the code
    cin.tie(NULL); //speeding up the code
    int m, n; //amount of elements and element
    cin>>m; //get the amount of elements
    vector<int> vec; //main vector
    vector<int> res; //result vector
    for(int i = 0; i < m; i++){ //start filling the vector
        cin>>n; //get the element
        vec.push_back(n); //add the element to the vector
    } //stop filling the vector with elements
    for(int i = 0; i < m; i++){ //start checking process
        if(i % 2 != 0){ //check if the index of the element is odd
            res.push_back(vec[i]); //if it is, add the element to the result vector
        } //stop checking
        else{ //if the index of the element is even
            continue; //continue checking and do nothing
        } //stop the else condition
    } //stop checking process
    if(res.empty()){ //check if the result vector is empty
        cout<<"NO"<<endl; //if it is empty, print "NO"
    } //stop checking if the result vector is empty
    else{ //if the result vector is not empty
        cout<<res.size()<<endl; //print the amount of elements in the result vector
        for(int i = 0; i < res.size(); i++){ //start printing the elements of the result vector
            cout<<res[i]<<" "; //print the element
        } //stop printing the elements of the result vector
    } //stop the else condition
    return 0; //speeding up the code
} //main function code end
dərc olunub 19.01.24 10:19:15

include<iomanip>

include<iostream>

include<cmath>

using namespace std; int main() { long long n,m,f=0; cin>> n; long long a[n]; for(int i=0;i<n;i++){ cin>> m; a[i]=m; } for(int i=0;i<n;i++){ if(i%2!=0){ f=f+1;}} if(f==0){ cout << "NO";} else{ cout <<f<<endl; for(int i=0;i<n;i++){ if (i%2!=0){ cout <<a[i]<<" ";}} }}