-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Ansh04122001/main
update tic tac toe. py and cpp for c++
- Loading branch information
Showing
33 changed files
with
1,333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
int main() { | ||
// Declare a variable named 'input_string' to hold our input. | ||
string input_string; | ||
|
||
// Read a full line of input from stdin (cin) and save it to our variable, input_string. | ||
getline(cin, input_string); | ||
|
||
// Print a string literal saying "Hello, World." to stdout using cout. | ||
cout << "Hello, World." << endl; | ||
|
||
// TODO: Write a line of code here that prints the contents of input_string to stdout. | ||
cout<<input_string; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <limits> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int i = 4; | ||
double d = 4.0; | ||
string s = "HackerRank "; | ||
int j=0,sum1; double e,sum2=0.0; string t,sum3=""; | ||
|
||
// Declare second integer, double, and String variables. | ||
cin>>j>>e; | ||
cin.ignore(); getline(cin, t); | ||
// Read and save an integer, double, and String to your variables. | ||
// Note: If you have trouble reading the entire string, please go back and review the Tutorial closely. | ||
sum1=i+j; | ||
printf("%d\n",sum1); | ||
sum2=d+e; | ||
// Print the sum of both integer variables on a new line. | ||
cout<<fixed<<setprecision(1)<<sum2<<"\n"; | ||
sum3=s+t; | ||
// Print the sum of the double variables on a new line. | ||
cout<<sum3; | ||
// Concatenate and print the String variables on a new line | ||
// The 's' variable above should be printed first. | ||
|
||
return 0;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
int main() | ||
{ | ||
int n; | ||
cin >> n; | ||
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | ||
int rem=0,s=0,t=0; | ||
|
||
|
||
while(n>0) | ||
{ | ||
rem=n%2; | ||
n=n/2; | ||
if(rem==1) | ||
{ s++; | ||
if(s>=t) | ||
|
||
t=s; | ||
|
||
} | ||
else{ | ||
|
||
s=0; | ||
} | ||
} | ||
cout<<t; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
int main() | ||
{ | ||
vector<vector<int>> arr(6); | ||
for (int i = 0; i < 6; i++) { | ||
arr[i].resize(6); | ||
|
||
for (int j = 0; j < 6; j++) { | ||
cin >> arr[i][j]; | ||
} | ||
|
||
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | ||
} | ||
int temp_sum;int max_sum = 0; | ||
|
||
for(int i = 0; i < 4; i++) { | ||
for(int j = 0; j < 4; j++) { | ||
temp_sum = 0; | ||
// top row | ||
temp_sum += arr[i][j]; | ||
temp_sum += arr[i][j+1]; | ||
temp_sum += arr[i][j+2]; | ||
//middle | ||
temp_sum += arr[i+1][j+1]; | ||
//bottom row | ||
temp_sum += arr[i+2][j]; | ||
temp_sum += arr[i+2][j+1]; | ||
temp_sum += arr[i+2][j+2]; | ||
|
||
//if first hourglass, set as max | ||
if(temp_sum > max_sum || i == 0 && j == 0) | ||
max_sum = temp_sum; | ||
} | ||
} | ||
cout << max_sum; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
|
||
class Person{ | ||
protected: | ||
string firstName; | ||
string lastName; | ||
int id; | ||
public: | ||
Person(string firstName, string lastName, int identification){ | ||
this->firstName = firstName; | ||
this->lastName = lastName; | ||
this->id = identification; | ||
} | ||
void printPerson(){ | ||
cout<< "Name: "<< lastName << ", "<< firstName <<"\nID: "<< id << "\n"; | ||
} | ||
|
||
}; | ||
|
||
class Student : public Person | ||
{ | ||
private: | ||
vector<int> testScores; | ||
int sum=0, subs=0; | ||
double avg=0.0; | ||
public: | ||
Student(string firstN, string lastN, int idS, vector<int> scores): Person(firstN,lastN,idS) | ||
{ | ||
this->testScores=scores; | ||
subs=testScores.size(); | ||
} | ||
char calculate() | ||
{ | ||
char g; | ||
for(unsigned int i=0; i<subs; ++i) | ||
{ | ||
sum+=testScores[i]; | ||
} | ||
avg=sum/subs; | ||
if (avg>=90 && avg<=100) | ||
g='O'; | ||
else if(avg>=80 && avg<=90) | ||
g='E'; | ||
else if(avg>=70 && avg<=80) | ||
g='A'; | ||
else if(avg>=55 && avg<=75) | ||
g='P'; | ||
else if(avg>=40 && avg<=55) | ||
g='D'; | ||
else if(avg<40) | ||
g= 'T'; | ||
return g; | ||
} | ||
|
||
}; | ||
|
||
int main() { | ||
string firstName; | ||
string lastName; | ||
int id; | ||
int numScores; | ||
cin >> firstName >> lastName >> id >> numScores; | ||
vector<int> scores; | ||
for(int i = 0; i < numScores; i++){ | ||
int tmpScore; | ||
cin >> tmpScore; | ||
scores.push_back(tmpScore); | ||
} | ||
Student* s = new Student(firstName, lastName, id, scores); | ||
s->printPerson(); | ||
cout << "Grade: " << s->calculate() << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <string> | ||
using namespace std; | ||
class Book{ | ||
protected: | ||
string title; | ||
string author; | ||
public: | ||
Book(string t,string a){ | ||
title=t; | ||
author=a; | ||
} | ||
virtual void display()=0; | ||
|
||
}; | ||
|
||
// Write your MyBook class here | ||
class MyBook : Book{ | ||
int price; | ||
public: | ||
string title; | ||
string author; | ||
MyBook(string title_,string author_,int price_) : Book(title_,author_) ,price(price_){ | ||
|
||
} | ||
virtual void display(){ | ||
cout<<"Title: "<<Book::title<<"\n"<<"Author: "<<Book::author<<"\n"<<"Price: "<<price; | ||
} | ||
|
||
|
||
|
||
}; | ||
// Class Constructor | ||
// | ||
// Parameters: | ||
// title - The book's title. | ||
// author - The book's author. | ||
// price - The book's price. | ||
// | ||
// Write your constructor here | ||
|
||
|
||
// Function Name: display | ||
// Print the title, author, and price in the specified format. | ||
// | ||
// Write your method here | ||
|
||
// End class | ||
|
||
int main() { | ||
string title,author; | ||
int price; | ||
getline(cin,title); | ||
getline(cin,author); | ||
cin>>price; | ||
MyBook novel(title,author,price); | ||
novel.display(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
class Difference { | ||
private: | ||
vector<int> elements; | ||
|
||
public: | ||
int maximumDifference; | ||
|
||
// Add your code here | ||
Difference(vector<int> a ) | ||
{ | ||
elements = a; | ||
} | ||
void computeDifference(){ | ||
short int i, max = 0, min = 101; | ||
for(i = 0; i < elements.size(); ++i) | ||
max = elements[i] > max ? elements[i] : max; | ||
for(i = 0; i < elements.size(); ++i) | ||
min = elements[i] < min ? elements[i] : min; | ||
maximumDifference = max - min; | ||
} | ||
}; // End of Difference class | ||
|
||
int main() { | ||
int N; | ||
cin >> N; | ||
|
||
vector<int> a; | ||
|
||
for (int i = 0; i < N; i++) { | ||
int e; | ||
cin >> e; | ||
|
||
a.push_back(e); | ||
} | ||
|
||
Difference d(a); | ||
|
||
d.computeDifference(); | ||
|
||
cout << d.maximumDifference; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <iostream> | ||
#include <cstddef> | ||
using namespace std; | ||
class Node | ||
{ | ||
public: | ||
int data; | ||
Node *next; | ||
Node(int d){ | ||
data=d; | ||
next=NULL; | ||
} | ||
}; | ||
class Solution{ | ||
public: | ||
|
||
Node* insert(Node *head,int data) | ||
{ | ||
Node** pp = &head; // pp is the pointer to the pointer head | ||
while(*pp) // While head is not null (the content of pp is not null) | ||
pp = &((*pp)->next); // pp receive the address of the pointer to the next node | ||
*pp = new Node(data); // In this moment the content of pp is the address to the last node | ||
return head; | ||
|
||
//Complete this method | ||
} | ||
|
||
void display(Node *head) | ||
{ | ||
Node *start=head; | ||
while(start) | ||
{ | ||
cout<<start->data<<" "; | ||
start=start->next; | ||
} | ||
} | ||
}; | ||
int main() | ||
{ | ||
Node* head=NULL; | ||
Solution mylist; | ||
int T,data; | ||
cin>>T; | ||
while(T-->0){ | ||
cin>>data; | ||
head=mylist.insert(head,data); | ||
} | ||
mylist.display(head); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
int main() | ||
{ | ||
string S; | ||
cin >> S; | ||
try | ||
{ | ||
int n = stoi(S); | ||
cout << n << endl; | ||
} | ||
catch (exception a) | ||
{ | ||
cout << "Bad String"; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.