If you are having any problem regarding the output or evaluation in Elab, Then check your code here.
Table of Contents
Table of Content
[CODE SOURCE : GOOGLE ]
Play with Permutations
#include <iostream>
#include <algorithm>
int main()
{
std::string s;
std::cin>>s;
while (1)
{
std::cout << s <<"\n";
if (!std::next_permutation(s.begin(),s.end()))
break;
}
return 0;
}
Vector Iterator
#include <vector>
#include <iterator>
using namespace std;
int main() {
int num,n;
cin>>n;
Use the code : Miru2021
vector<int>MyVector;for(int i=0;i<n;i++)
{
cin>>num;
MyVector.push_back(num);
}
vector<int>::iterator ptr;
for (ptr = MyVector.begin(); ptr < MyVector.end(); ptr++)
cout << *ptr << " ";
/*for(int i=0;i<n;i++)
{
cout<<MyVector[i]<<" ";
}*/
cout<<endl;
// vector<int>::reverse_iterator;
vector<int>::reverse_iterator ptr1;
for (ptr1 = MyVector.rbegin(); ptr1 < MyVector.rend(); ptr1++)
cout << *ptr1 << " ";
/* for(int i=n-1;i>=0;i–)
{
cout<<MyVector[i]<<" ";
}*/
return 0;
}
My Pair
#include <iostream>
using namespace std;
int main()
{
Click on the image to get an offer!
Use the code: miru2021
pair<int,string> mypair;
cin >> mypair.first;
cin >> mypair.second;
cout << mypair.first << " " << mypair.second;
return 0;
}
Remove Duplicate
#include <bits/stdc++.h>
#include <list>
using namespace std;
void showlist(list<int> demolist)
{
list<int>::iterator it;
for (it = demolist.begin(); it != demolist.end(); ++it)
cout << *it << " ";
//cout << '\n';
}
int main()
{
list<int> demolist;
int n, j, i;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> j;
demolist.push_back(j);
}
demolist.unique();
demolist.sort();
showlist(demolist);
return 0;
}
Balancing
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;
int main() {
string str;
cin>>str;
stack<char> mystack;
int l=str.size();
bool flag=true;
//cout << str << "\n";
int ref;
for (int i=0; i<l; i++) {
if (mystack.size()==0) {
mystack.push(str[i]);
continue;
}
ref=(int)str[i];
if (ref>(int)mystack.top()) {
if (ref-mystack.top() <=2) {
mystack.pop();
}
Use the code: Miru2021
else {
cout << "NO\n";
return 0;
}
}
else {
mystack.push(str[i]);
}
}
if (mystack.size()==0) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
return 0;
}
Programmer
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
//push_back()
int main() {
int num,n;
cin>>n;
vector<int> myvector;
for(int i=0;i<n;i++)
{
cin>>num;
myvector.push_back(num);
}
vector<int>::iterator ptr;
for(ptr=myvector.begin(); ptr<myvector.end();ptr++)
cout << *ptr <<" ";
cout<<endl;
vector<int>::reverse_iterator ptr1;
for (ptr1=myvector.rbegin();ptr1<myvector.rend();ptr1++)
cout << *ptr1 <<" ";
return 0;
}
Sort Game
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
vector<int>v;
while(n–) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
for (auto i:v) {
cout << i << " ";
}
return 0;
}
Vector to Heap
#include<algorithm>
#include<vector>
using namespace std;
vector<int> myvector;
int main()
{
int n,i;
cin>>n;
int input=0;
for(i=0;i<n;i++)
{
cin>>input;
myvector.push_back(input);
}
make_heap(myvector.begin(), myvector.end());
// Displaying the maximum element of heap
// using front()
cout << myvector.front() << endl;
return 0;
}
Play with Streams
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str)
{
stringstream ss(str);
vector<int> result;
int temp_int;
char temp_char;
ss >> temp_int;
result.push_back(temp_int);
while (ss >> temp_char)
{
ss >> temp_int;
result.push_back(temp_int);
}
return result;
}
int main()
{
string str;
cin >> str;
vector<int> integers = parseInts(str);
for (int i = 0; i < integers.size(); i++)
{
cout << integers[i] << "\n";
}
return 0;
}
Sets
#include <iostream>
#include <set>
using namespace std;
int main() {
int n;
set<int>s;
cin >> n;
while(n–){
int x,y;
cin >> y >> x;
if(y == 1){
s.insert(x);
} else if(y == 2){
s.erase(x);
} else {
auto itr = s.find(x);
if(distance(itr,s.end()) == 0){
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
}
return 0;
}
Deque
#include <cstdio>
#include <deque>
#include <algorithm>
#include <iostream>
using namespace std;
int a[1000000];
int x[1000000], y[1000000];
deque<int> dq2;
int main()
{
int T;
cin >> T;
while(T–){
dq2.clear();
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < k – 1; i++){
while (dq2.size() && a[dq2[dq2.size() – 1]] <= a[i]) dq2.pop_back();
dq2.push_back(i);
}
for (int i = 0, j; (j = i + k – 1) < n; i++){
while (dq2.size() && a[dq2[dq2.size() – 1]] <= a[j]) dq2.pop_back();
dq2.push_back(j);
y[i] = a[dq2[0]];
if (dq2[0] == i) dq2.pop_front();
}
for (int i = 0; i <= n – k; i++) printf("%d%c", y[i], i == n – k ? '\n' : ' ');
}
return (0);
}
Use the code: Miru2021
Swapping two Functions
#include <stack>
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
stack<int> mystack1;
stack<int> mystack2;
vector<int>i;
vector<int>j;
int n,k,a;
cin>>n;
for(k=0;k<n;k++)
{
cin>>a;
mystack1.push(a);
}
for(k=0;k<n;k++)
{
cin>>a;
mystack2.push(a);
}
mystack1.swap(mystack2);
cout<<"";
while (!mystack1.empty()) {
cout<<mystack1.top()<<" ";
mystack1.pop();
}
reverse(i.begin(),i.end());
reverse(j.begin(),j.end());
cout<<endl;
while (!mystack2.empty()) {
cout<<mystack2.top()<<" ";
mystack2.pop();
}
return 0;
}
MARKS AND VECTOR
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector myvector;
int n, x;
cin >> n;
while (n–)
{
cin >> x;
myvector.push_back(x);
}
cout << *min_element(myvector.begin(), myvector.end()) << " ";
cout << *max_element(myvector.begin(), myvector.end());
}
Playing With Sets
#include<bits/stdc++.h>
#include<iostream>
#include<set>
using namespace std;
int main(){
set<int>s;
int size;
cin >> size;
int a = size;
set<int>:: iterator it;
for(int i = 0; i < size; i++){
int b;
cin >> b;
s.insert(b);
}
int c;
cin >> c;
if(s.find(c) != s.end()){
cout << "Element "<< c << " found in the set\n";
}else{
cout << "No Element Found\n";
}
for(set<int>::iterator itr = s.begin(); itr != s.end(); itr++){
cout << *itr << " ";
}
cout << endl;
cout << "Size="<< size << endl;
return 0;
}
Click on the image to get an offer!
Use the code: miru2021