-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCP STL in oneshot...cpp
210 lines (181 loc) · 3.24 KB
/
CP STL in oneshot...cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
------------------push_back/pop_back/clear-----------
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v;
v.push_back(5);
v.push_back(6);
v.push_back(3);
//cout<<v[0]<<" "<<v[1]<<" "<<v[2];
cout<< v.size()<<endl;
v.pop_back();
cout<< v.size()<<endl;
v.push_back(0);
v.clear();
cout<< v.size()<<endl;
cout<<endl;
//cout<<v[0]<<" "<<v[1]<<" "<<v[2];
}
*/
/*
-----------------vector<int> v(50, 7);-- what does it means---------
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v(50, 7); ///{7,7,7,7,7.........upto 50 times}
cout<<v[23]; //v[23]==7........
}
*/
/*------------Sort Function---------------
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v;
vector<int> p;
int arr[n];
for(int i=1;i<=n;i++)
{
cin>>arr[i];
if(arr[i]%2==0)
{
v.push_back(i);
}
else
{
p.push_back(i);
}
}
sort(v.begin(),v.end());
for (int i=0;i<v.size();i++)
{
cout<<v[i];
}
// cout<<x<<" ";
cout<<endl;
//for (auto u : p)
// cout<<u<<" ";
sort(p.begin(),p.end());
for (int i=0;i<p.size();i++)
{
cout<<p[i];
}
}
*/
/*-----------------PAIR in STL-----------------
#include <bits/stdc++.h>
using namespace std;
int main()
{
//#ifndef ONLINE_JUDGE
//freopen("input.txt","r", stdin);
//freopen("output.txt","w", stdout);
//#endif
pair<int, char> PAIR1;
PAIR1.first = 100;
PAIR1.second = 'G';
cout << PAIR1.first << " ";
cout << PAIR1.second << endl;
return 0;
}
///////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<pair<int, string>> v;//{score, names}
//
///
//
//
sort(v.begin(), v.end());
return 0;
}
*/
/*-------------------------set operator-----------------
#include <bits/stdc++.h>
using namespace std;
int main()
{
set<int> s;
s.insert(10);
s.insert(15);
cout<<s.count(10)<<endl;
cout<<s.count(9)<<endl;
cout<<s.count(12)<<endl;
cout<<s.count(3)<<endl;
cout<<s.count(15)<<endl;
s.erase(10);
cout<<s.count(10)<<endl;
}
*/
/*-------------Map in STL--------------
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<int,int> m;
cout<<m.size()<<endl;
cout<<m[15]<<endl;//instantly create the element and the value will bw 0....
cout<<m.size()<<endl;
}
-------------------frequency counter is the best thing of Map----------
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<int,int> freq;
freq[10]++;
freq[10]++;
freq[10]++;
freq[10]++;
cout<<freq[10]<<" "<<freq[4]<<endl;
}
---------------no.1 problem in map----------
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<string, int> freq;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
if(freq[s] == 0)
{
cout<<"OK"<<endl;
}
else
{
cout<< s <<freq[s]<<endl;
}
freq[s]++;
}
}
*/
//------------------using of SET--------------------
#include <bits/stdc++.h>
using namespace std;
int main()
{
set<int>s;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
s.insert(x);
}
for(int x:s)
{
cout<<x<<" ";
}
}