Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3d061bd
hackerrank problems(intro and strings)
Harshit9369 Mar 23, 2023
5d1965f
Add files via upload
Harshit9369 Mar 23, 2023
54cfdf7
Delete intro_arrays.cpp
Harshit9369 Mar 23, 2023
6db01e6
Delete intro_conditionals.cpp
Harshit9369 Mar 23, 2023
115b9ea
Delete intro_datatypes.cpp
Harshit9369 Mar 23, 2023
d298dc5
Delete intro_forloop.cpp
Harshit9369 Mar 23, 2023
5943d19
Delete intro_functions.cpp
Harshit9369 Mar 23, 2023
f75e370
Delete intro_helloworld.cpp
Harshit9369 Mar 23, 2023
07af2f8
Delete intro_io.cpp
Harshit9369 Mar 23, 2023
52a0c1d
Delete intro_ptr.cpp
Harshit9369 Mar 23, 2023
da3c505
Delete intro_varsizarr.cpp
Harshit9369 Mar 23, 2023
0064075
Delete strings_attparse.cpp
Harshit9369 Mar 23, 2023
6efebe8
Delete strings_sstream
Harshit9369 Mar 23, 2023
2b1cd27
Delete strings_sstream.cpp
Harshit9369 Mar 23, 2023
bdcd176
Delete strings_str.cpp
Harshit9369 Mar 23, 2023
2034e58
Add files via upload
Harshit9369 Mar 23, 2023
dfbd1b1
Create Solutions_hackerrank_intro+strings
Harshit9369 Mar 23, 2023
978af8f
Delete Solutions_hackerrank_intro+strings
Harshit9369 Mar 23, 2023
d915606
Create intro_helloworld.cpp
Harshit9369 Mar 23, 2023
fb87336
Create intro.cpp
Harshit9369 Mar 23, 2023
a92aaf5
Delete intro.cpp
Harshit9369 Mar 23, 2023
3f24467
Add files via upload
Harshit9369 Mar 23, 2023
229b7bc
Delete intro_arrays.cpp
Harshit9369 Mar 23, 2023
8fee455
Delete intro_conditionals.cpp
Harshit9369 Mar 23, 2023
62ee917
Delete intro_datatypes.cpp
Harshit9369 Mar 23, 2023
3e68d96
Delete intro_forloop.cpp
Harshit9369 Mar 23, 2023
f40ab94
Delete intro_functions.cpp
Harshit9369 Mar 23, 2023
94d224c
Delete intro_helloworld.cpp
Harshit9369 Mar 23, 2023
05cb5b0
Delete intro_io.cpp
Harshit9369 Mar 23, 2023
784a170
Delete intro_ptr.cpp
Harshit9369 Mar 23, 2023
543aeb8
Delete intro_varsizarr.cpp
Harshit9369 Mar 23, 2023
eccb28c
Delete strings_attparse.cpp
Harshit9369 Mar 23, 2023
391377b
Delete strings_sstream.cpp
Harshit9369 Mar 23, 2023
cd14e7b
Delete strings_str.cpp
Harshit9369 Mar 23, 2023
937bb1e
Delete intro_arrays.cpp
Harshit9369 Mar 23, 2023
25942ec
Delete intro_conditionals.cpp
Harshit9369 Mar 23, 2023
b892f4f
Delete intro_datatypes.cpp
Harshit9369 Mar 23, 2023
d7341bf
Delete intro_forloop.cpp
Harshit9369 Mar 23, 2023
8102ba2
Delete intro_functions.cpp
Harshit9369 Mar 23, 2023
68b608d
Delete intro_helloworld.cpp
Harshit9369 Mar 23, 2023
b5dfe48
Delete intro_io.cpp
Harshit9369 Mar 23, 2023
cea9261
Delete intro_ptr.cpp
Harshit9369 Mar 23, 2023
5bcd154
Delete intro_varsizarr.cpp
Harshit9369 Mar 23, 2023
32e586f
Delete strings_attparse.cpp
Harshit9369 Mar 23, 2023
166384a
Delete strings_sstream.cpp
Harshit9369 Mar 23, 2023
e4f0047
Delete strings_str.cpp
Harshit9369 Mar 23, 2023
a0ae77d
Delete strings_attparse.cpp
Harshit9369 Mar 23, 2023
3223798
Rename intro_datatypes.cpp to Data_Types.cpp
Harshit9369 Mar 26, 2023
498a18f
Rename intro_forloop.cpp to For_Loop.cp
Harshit9369 Mar 26, 2023
5f3c479
Rename intro_arrays.cpp to Arrays.cpp
Harshit9369 Mar 26, 2023
8023d56
Rename intro_conditionals.cpp to Conditionals.cpp
Harshit9369 Mar 26, 2023
30ff87d
Rename intro_functions.cpp to Functions.cpp
Harshit9369 Mar 26, 2023
93aea32
Rename intro_helloworld.cpp to Hello_World.cpp
Harshit9369 Mar 26, 2023
cb1f5bf
Rename intro_io.cpp to Input_Output.cpp
Harshit9369 Mar 26, 2023
05b3523
Rename intro_ptr.cpp to Pointers.cpp
Harshit9369 Mar 26, 2023
f9a08a0
Rename intro_varsizarr.cpp to Variable_Size_Arrays.cpp
Harshit9369 Mar 26, 2023
1e77b64
Rename strings_sstream.cpp to StringStream.cpp
Harshit9369 Mar 26, 2023
bb108db
Rename strings_str.cpp to Strings.cpp
Harshit9369 Mar 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hackerrank_solutions_intro+strings/Arrays.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++){
cin >> a[i] ;

}
for (int i = n-1 ; i >= 0 ; i--){
cout << a[i] << " ";
}
return 0;
}
18 changes: 18 additions & 0 deletions hackerrank_solutions_intro+strings/Conditionals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
if (n == 1) cout << "one" << endl;
else if (n == 2) cout << "two" << endl;
else if (n == 3) cout << "three" << endl;
else if (n == 4) cout << "four" << endl;
else if (n == 5) cout << "five" << endl;
else if (n == 6) cout << "six" << endl;
else if (n == 7) cout << "seven" << endl;
else if (n == 8) cout << "eight" << endl;
else if (n == 9) cout << "nine" << endl;
else cout << "Greater than 9" << endl;
}

31 changes: 31 additions & 0 deletions hackerrank_solutions_intro+strings/Data_Types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int i;
long l;
char cr;
char spa;
float ft;
double db;
scanf("%d",&i);
scanf("%ld\n",&l);
//scanf("%c",&spa);
scanf("%c",&cr);

scanf("%f",&ft);
scanf("%lf",&db);
printf("%d\n",i);
printf("%ld\n",l);
printf("%c\n",cr);
printf("%.3f\n",ft);
printf("%.9lf\n",db);

return 0;
}
28 changes: 28 additions & 0 deletions hackerrank_solutions_intro+strings/For_Loop.cp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
// Complete the code.
int a, b;
cin >> a >> b;
for (int i = a; i <= b ; i++){
if (i <= 9){
if (i == 1) cout << "one" << endl;
else if (i == 2) cout << "two" << endl;
else if (i == 3) cout << "three" << endl;
else if (i == 4) cout << "four" << endl;
else if (i == 5) cout << "five" << endl;
else if (i == 6) cout << "six" << endl;
else if (i == 7) cout << "seven" << endl;
else if (i == 8) cout << "eight" << endl;
else cout << "nine" << endl;

}
else {
if (i%2 == 0) cout << "even" << endl;
else cout << "odd" << endl;
}
}
return 0;
}
38 changes: 38 additions & 0 deletions hackerrank_solutions_intro+strings/Functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <cstdio>
using namespace std;

/*
Add `int max_of_four(int a, int b, int c, int d)` here.
*/
void max_of_four(int a, int b, int c, int d){
if(a > b){
if (a > c){
if (a > d) cout << a ;
else cout << d;
}
else{
if (c > d) cout << c;
else cout << d;
}
}
else {
if (b > c){
if (b > d) cout << b;
else cout << d;
}
else{
if (c > d) cout << c;
else cout << d;
}
}
}

int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
max_of_four(a, b, c, d);
cout << endl;

return 0;
}
8 changes: 8 additions & 0 deletions hackerrank_solutions_intro+strings/Hello_World.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
printf("Hello, World!");
return 0;
}
17 changes: 17 additions & 0 deletions hackerrank_solutions_intro+strings/Input_Output.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int a, b, c;
cin >> a >> b >> c;
int sum;
sum = a + b + c;
cout << sum << endl;
return 0;
}
11 changes: 11 additions & 0 deletions hackerrank_solutions_intro+strings/Pointers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int x = a + b;
int y = a - b;
int z = abs(y);
cout << x << endl << z << endl;
return 0;
}
25 changes: 25 additions & 0 deletions hackerrank_solutions_intro+strings/StringStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
using namespace std;

vector<int> parseInts(string str) {
// Complete this function
vector<int> parse;
stringstream ss(str);
int t;
char c;
while(ss >> t){
parse.push_back(t);
ss >> c;
}
return parse;
}

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;
}
20 changes: 20 additions & 0 deletions hackerrank_solutions_intro+strings/Strings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
// Complete the program
string a, b;
cin >> a;
cin >> b;
int c, d;
c = a.size();
d = b.size();
cout << c << " " << d << endl;
string x = a + b;
cout << x << endl;
char ch = a[0];
a[0] = b[0];
b[0] = ch;
cout << a << " " << b << endl;
return 0;
}
29 changes: 29 additions & 0 deletions hackerrank_solutions_intro+strings/Variable_Size_Arrays.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int n, q;
cin >> n >> q;
vector<int> k(n);
vector<vector<int>> a(n);
for (int i = 0; i < n; i++){
cin >> k[i];
a[i].resize(k[i]);
//took help from gfg for this...
for(int j = 0 ; j < k[i]; j++){
cin >> a[i][j];
}
}

vector<vector<int>> que(q, vector<int>(2));
for (int i = 0; i < q; i++){
for (int j = 0 ; j < 2 ; j++){
cin >> que[i][j];
}
}
for (int i = 0; i < q; i++){
cout << a[que[i][0]][que[i][1]] << endl;
}

return 0;
}