Skip to content

Commit 828e524

Browse files
Print X and Inserting inside vector problem solved
1 parent f51a3e5 commit 828e524

8 files changed

+61
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"Insert it","group":"HackerRank - Assignment 01 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-01-a-basic-data-structure-a-batch-05/challenges/insert-the-vector","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5\n2 3 4 5 6\n3\n10 20 30\n3\n","output":"2 3 4 10 20 30 5 6\n","id":1720457307283},{"input":"5\n2 3 4 5 6\n3\n10 20 30\n0\n","output":"10 20 30 2 3 4 5 6\n","id":1720457307201},{"input":"4\n3 4 5 6\n3\n10 20 30\n4\n","output":"3 4 5 6 10 20 30\n","id":1720457307230}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"InsertIt"}},"batch":{"id":"6b38f826-f801-4885-9a41-cc20efb0e01f","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Insert_it.cpp"}
1+
{"name":"Insert it","group":"HackerRank - Assignment 01 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-01-a-basic-data-structure-a-batch-05/challenges/insert-the-vector","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5\n2 3 4 5 6\n3\n10 20 30\n3\n","output":"2 3 4 10 20 30 5 6\n","id":1720457307283},{"input":"5\n2 3 4 5 6\n3\n10 20 30\n0\n","output":"10 20 30 2 3 4 5 6\n","id":1720457307201},{"id":1720457307230,"input":"4\n3 4 5 6\n3\n10 20 30\n4\n","output":"3 4 5 6 10 20 30\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"InsertIt"}},"batch":{"id":"6b38f826-f801-4885-9a41-cc20efb0e01f","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Insert_it.cpp"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Printing X","group":"HackerRank - Assignment 01 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-01-a-basic-data-structure-a-batch-05/challenges/printing-x","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5\n","output":"\\ /\n \\ /\n X\n / \\\n/ \\\n","id":1720458711069},{"input":"7\n","output":"\\ /\n \\ /\n \\ /\n X\n / \\\n / \\\n/ \\\n","id":1720458711100},{"input":"3\n","output":"\\ /\n X\n/ \\\n","id":1720458711116},{"input":"1\n","output":"X\n","id":1720458711142}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"PrintingX"}},"batch":{"id":"9bf40bd6-eda6-4e05-958e-d80f55fd681e","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Printing_X.cpp"}

Insert_it.bin

88.8 KB
Binary file not shown.

Insert_it.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n, m;
7+
cin >> n;
8+
vector<int> a(n);
9+
vector<int> b(m);
10+
for (int i = 0; i < n; i++)
11+
{
12+
cin >> a[i];
13+
}
14+
15+
cin >> m;
16+
for (int i = 0; i < m; i++)
17+
{
18+
cin >> b[i];
19+
}
20+
int x;
21+
cin >> x;
22+
for (int i = 0; i < m; i++)
23+
{
24+
a.insert(a.begin() + x + i, b[i]);
25+
}
26+
27+
for (int i = 0; i < n + m; i++)
28+
{
29+
cout << a[i] << " ";
30+
}
31+
32+
return 0;
33+
}

Printing_X.bin

48.4 KB
Binary file not shown.

Printing_X.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int N;
7+
cin >> N;
8+
9+
for (int i = 0; i < N; ++i)
10+
{
11+
for (int j = 0; j < N; ++j)
12+
{
13+
if (i == j && i == N / 2)
14+
cout << "X";
15+
else if (i == j)
16+
cout << "\\";
17+
else if (i + j == N - 1)
18+
cout << "/";
19+
else
20+
cout << " ";
21+
}
22+
cout << endl;
23+
}
24+
25+
return 0;
26+
}

input.txt

-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
3
2-
5
3-
2 4 6 7 10
4-
8
5-
1 100 101 120 120 121 1000 1000
6-
4
7-
100 1 102 12

output.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
YES
2-
YES
3-
NO

0 commit comments

Comments
 (0)