Skip to content

Commit 9e84a88

Browse files
authored
Merge pull request #693 from simranquirky/master
Added solution of 30daysOfCode to hackerrank solutions folder
2 parents 8188e9b + 4518a4f commit 9e84a88

12 files changed

+696
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Task
2+
To complete this challenge, you must save a line of input from stdin to a variable, print Hello, World. on a single line, and finally print the value of your variable on a second line.
3+
4+
You've got this!
5+
6+
Note: The instructions are Java-based, but we support submissions in many popular languages. You can switch languages using the drop-down menu above your editor, and the variable may be written differently depending on the best-practice conventions of your submission language.
7+
8+
Input Format
9+
10+
A single line of text denoting (the variable whose contents must be printed).
11+
12+
Output Format
13+
14+
Print Hello, World. on the first line, and the contents of on the second line.
15+
16+
Sample Input
17+
18+
Welcome to 30 Days of Code!
19+
Sample Output
20+
21+
Hello, World.
22+
Welcome to 30 Days of Code!
23+
Explanation
24+
25+
On the first line, we print the string literal Hello, World.. On the second line, we print the contents of the variable which, for this sample case, happens to be Welcome to 30 Days of Code!. If you do not print the variable's contents to stdout, you will not pass the hidden test case. */
26+
#include <cmath>
27+
#include <cstdio>
28+
#include <vector>
29+
#include <iostream>
30+
#include <algorithm>
31+
using namespace std;
32+
int main() {
33+
// Declare a variable named 'input_string' to hold our input.
34+
string input_string;
35+
36+
// Read a full line of input from stdin (cin) and save it to our variable, input_string.
37+
getline(cin, input_string);
38+
39+
// Print a string literal saying "Hello, World." to stdout using cout.
40+
cout << "Hello, World." << endl;
41+
42+
// TODO: Write a line of code here that prints the contents of input_string to stdout.
43+
44+
return 0;
45+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Task
2+
Complete the code in the editor below. The variables , , and are already declared and initialized for you. You must:
3+
4+
Declare variables: one of type int, one of type double, and one of type String.
5+
Read lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables.
6+
Use the operator to perform the following operations:
7+
Print the sum of plus your int variable on a new line.
8+
Print the sum of plus your double variable to a scale of one decimal place on a new line.
9+
Concatenate with the string you read as input and print the result on a new line.
10+
Note: If you are using a language that doesn't support using for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.
11+
12+
Input Format
13+
14+
The first line contains an integer that you must sum with .
15+
The second line contains a double that you must sum with .
16+
The third line contains a string that you must concatenate with .
17+
18+
Output Format
19+
20+
Print the sum of both integers on the first line, the sum of both doubles (scaled to decimal place) on the second line, and then the two concatenated strings on the third line.
21+
22+
Sample Input
23+
24+
12
25+
4.0
26+
is the best place to learn and practice coding!
27+
Sample Output
28+
29+
16
30+
8.0
31+
HackerRank is the best place to learn and practice coding!
32+
Explanation
33+
34+
When we sum the integers 4 and 12 , we get the integer 16 .
35+
When we sum the floating-point numbers 4.0 and 4.0, we get 8.0.
36+
When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.
37+
38+
You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above and reading input from stdin. */
39+
40+
#include <iostream>
41+
#include <iomanip>
42+
#include <limits>
43+
44+
using namespace std;
45+
46+
int main() {
47+
int i = 4;
48+
double d = 4.0;
49+
string s = "HackerRank ";
50+
int j;
51+
scanf("%d",&j);
52+
double k;
53+
scanf("%lf",&k);
54+
char s2[100];
55+
scanf("%*[\n] %[^\n]",s2);
56+
57+
printf("%d \n",i+j);
58+
printf("%.1f\n",d+k);
59+
printf("%s%s\n",s,s2);
60+
61+
return 0;
62+
63+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Sample Input 1
3+
4+
5
5+
Sample Output 1
6+
7+
1
8+
Sample Input 2
9+
10+
13
11+
Sample Output 2
12+
13+
2
14+
15+
16+
Input Format
17+
18+
A single integer,n .
19+
20+
Output Format
21+
22+
Print a single base-10 integer that denotes the maximum number of consecutive 1's in the binary representation of n. */
23+
24+
25+
#include <assert.h>
26+
#include <limits.h>
27+
#include <math.h>
28+
#include <stdbool.h>
29+
#include <stddef.h>
30+
#include <stdint.h>
31+
#include <stdio.h>
32+
#include <stdlib.h>
33+
#include <string.h>
34+
35+
int main()
36+
{
37+
int n;
38+
scanf("%d",&n);
39+
40+
int rem = 0;
41+
int curr = 0;
42+
int max = 0;
43+
44+
45+
while(n > 0) {
46+
rem = n % 2;
47+
if(rem == 1) {
48+
curr++;
49+
if(curr >= max) {
50+
max = curr;
51+
}
52+
} else {
53+
curr = 0;
54+
}
55+
n = n / 2;
56+
}
57+
58+
printf("%d\n", max);
59+
60+
return 0;
61+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Sample Input
3+
4+
1 1 1 0 0 0
5+
0 1 0 0 0 0
6+
1 1 1 0 0 0
7+
0 0 2 4 4 0
8+
0 0 0 2 0 0
9+
0 0 1 2 4 0
10+
Sample Output
11+
12+
19
13+
14+
Input Format
15+
16+
There are 6 lines of input, where each line contains 6 space-separated integers that describe the 2D Array A.
17+
18+
Output Format
19+
20+
Print the maximum hourglass sum in A. */
21+
22+
#include <assert.h>
23+
#include <limits.h>
24+
#include <math.h>
25+
#include <stdbool.h>
26+
#include <stddef.h>
27+
#include <stdint.h>
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
32+
int main() {
33+
int N = 6;
34+
int arr[N][N];
35+
36+
for(int arr1 = 0; arr1 < N; arr1++) {
37+
for(int arr2 = 0; arr2 < N; arr2++) {
38+
scanf("%d",&arr[arr1][arr2]);
39+
}
40+
}
41+
42+
int max = -500;
43+
int curr = 0;
44+
for(int arr1 = 0; arr1 < N - 2; arr1++) {
45+
for(int arr2= 0; arr2 < N - 2; arr2++) {
46+
int a = arr[arr1][arr2];
47+
int b = arr[arr1][arr2 + 1];
48+
int c = arr[arr1][arr2 + 2];
49+
int d = arr[arr1 + 1][arr2 + 1];
50+
int e = arr[arr1 + 2][arr2];
51+
int f = arr[arr1 + 2][arr2 + 1];
52+
int g = arr[arr1+ 2][arr2 + 2];
53+
54+
curr = a + b + c + d + e + f + g;
55+
if(curr > max) {
56+
max = curr;
57+
}
58+
}
59+
}
60+
61+
printf("%d", max);
62+
63+
return 0;
64+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Sample Input
2+
3+
Heraldo Memelli 8135627
4+
2
5+
100 80
6+
7+
Sample Output
8+
9+
Name: Memelli, Heraldo
10+
ID: 8135627
11+
Grade: O
12+
13+
This student had scores to average:100 and 80 . The student's average grade is (100+80)/2=90. An average grade of 90 corresponds to the letter grade O, so the calculate() method should return the character'O'.
14+
*/
15+
16+
class Student extends Person
17+
{
18+
private int[] testScores;
19+
public Student(String firstName, String lastName, int id, int [] scores)
20+
{
21+
super(firstName, lastName, id);
22+
testScores = scores;
23+
}
24+
public char calculate()
25+
{
26+
double average = 0;
27+
for (int score : testScores)
28+
{
29+
average += score;
30+
}
31+
average /= testScores.length;
32+
33+
if (average >= 90)
34+
{
35+
return 'O';
36+
}
37+
else if (average >= 80)
38+
{
39+
return 'E';
40+
}
41+
else if (average >= 70)
42+
{
43+
return 'A';
44+
}
45+
else if (average >= 55)
46+
{
47+
return 'P';
48+
}
49+
else if (average >= 40)
50+
{
51+
return 'D';
52+
}
53+
else
54+
{
55+
return 'T';
56+
}}}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Task
2+
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. Round the result to the nearest integer.
3+
4+
Example
5+
6+
7+
8+
A tip of 15% * 100 = 15, and the taxes are 8% * 100 = 8. Print the value and return from the function.
9+
10+
Function Description
11+
Complete the solve function in the editor below.
12+
13+
solve has the following parameters:
14+
15+
int meal_cost: the cost of food before tip and tax
16+
int tip_percent: the tip percentage
17+
int tax_percent: the tax percentage
18+
Returns The function returns nothing. Print the calculated value, rounded to the nearest integer.
19+
20+
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result.
21+
22+
Sample Input
23+
24+
12.00
25+
20
26+
8
27+
Sample Output
28+
29+
15 */
30+
31+
#include <assert.h>
32+
#include <limits.h>
33+
#include <math.h>
34+
#include <stdbool.h>
35+
#include <stddef.h>
36+
#include <stdint.h>
37+
#include <stdio.h>
38+
#include <stdlib.h>
39+
#include <string.h>
40+
41+
char* readline();
42+
43+
// Complete the solve function below.
44+
void solve(double meal_cost, int tip_percent, int tax_percent) {
45+
double tip = meal_cost * tip_percent / 100;
46+
double tax = meal_cost * tax_percent / 100;
47+
int total =(int)round(meal_cost + tip + tax);
48+
printf("%d",total);
49+
}
50+
int main()
51+
{
52+
double mo;
53+
int tp,tp1;
54+
scanf("%lf",&mo);
55+
scanf("%d",&tp);
56+
scanf("%d",&tp1);
57+
solve(mo,tp,tp1);
58+
}

0 commit comments

Comments
 (0)