Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanish2409 committed Jul 25, 2021
0 parents commit 07fc555
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 0 deletions.
50 changes: 50 additions & 0 deletions butterfly_pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>

using namespace std;

int main() {

int n;
cin>>n;

for(int i = 1; i <=n; i++) {
for(int j = 1; j <= i; j++){
cout<<"*";
}

int spaces = 2*n - 2*i;

for(int j = 1; j <= spaces; j++){
cout<<" ";
}


for(int j = 1; j <= i; j++){
cout<<"*";
}

cout<<endl;
}

for(int i = n; i >= 1 ; i--) {
for(int j = 1; j <= i; j++){
cout<<"*";
}

int spaces = 2*n - 2*i;

for(int j = 1; j <= spaces; j++){
cout<<" ";
}


for(int j = 1; j <= i; j++){
cout<<"*";
}

cout<<endl;
}

cout<<endl;
return 0;
}
33 changes: 33 additions & 0 deletions codeforces/118_A_String_Task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;

int main() {

string str, str1 = "";

cin>>str;

multiset<char> vowels = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y'};

for(auto it = str.begin(); it != str.end(); it++) {

if(vowels.find(*it) != vowels.end()){
continue;
}else {
if(*it >= 65 && *it < 91) {
*it += 32;
}
str1 = str1 + "." + *it;
}
}
cout<<str1;

// Solution 2
// char c;

// while(cin>>c) {
// if(!strchr("aeiouyAEIOUY", c)) cout<<"."<<(char)tolower(c);
// }

return 0;
}
23 changes: 23 additions & 0 deletions codeforces/71_A_Way_to_Long_Words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
#include<string>

using namespace std;

int main() {
int n, len;
string s[100];

cin>>n;

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

for (int i = 0; i < n; i++) {
len = s[i].length();
if(len > 10 ) cout<<s[i][0]<<len - 2<<s[i][len - 1]<<"\n";
else cout<<s[i]<<"\n";
}

return 0;
}
22 changes: 22 additions & 0 deletions codeforces/977_A_wrong_subtraction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<iostream>

using namespace std;

int main() {

long long int n;
int k;
cin>>n>>k;

while(k--) {
if(n%10 > 0) {
--n;
}else {
n /= 10;
}
}

cout<<n;

return 0;
}
18 changes: 18 additions & 0 deletions codeforces/A_Watermelon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<iostream>

using namespace std;

int main() {
int w;

cin>>w;

if(w % 2 == 0 && w > 3) {
cout<<"YES";
} else {
cout<<"NO";
}


return 0;
}
21 changes: 21 additions & 0 deletions floyds_triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>

using namespace std;

int main() {

int n;
int counter = 0;

cin>>n;

for(int i = 0; i < n; i++) {
for(int j = 0; j <= i; j++) {
cout<<++counter;
}
cout<<endl;
}

cout<<endl;
return 0;
}
20 changes: 20 additions & 0 deletions half_pyramid_using_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

for(int i = 0; i < n; i++) {
for(int j = 0; j <= i; j++) {
cout<<i+1;
}
cout<<endl;
}

cout<<endl;
return 0;
}
24 changes: 24 additions & 0 deletions halp_pyramid_after_180_rotation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(j <= ((n-1) - (i + 1)) ){
cout<<" ";
}else {
cout<<'*';
}
}
cout<<endl;
}

cout<<endl;
return 0;
}
24 changes: 24 additions & 0 deletions hollow_rectangle_pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>

using namespace std;

int main() {

int row, col;

cin>>row>>col;

for(int i = 0; i < row; i++) {
for(int j = 0; j < col; j++) {
if(i == 0 || j == 0 || i == (row - 1) || j == (col - 1) ) {
cout<<'*';
}else {
cout<<" ";
}
}
cout<<endl;
}

cout<<endl;
return 0;
}
20 changes: 20 additions & 0 deletions inverted_half_pyramid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

for(int i = n - 1; i >= 0; i--) {
for(int j = i; j >= 0; j--) {
cout<<'*';
}
cout<<endl;
}

cout<<endl;
return 0;
}
61 changes: 61 additions & 0 deletions leetcode/645_set_mismatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include<bits/stdc++.h>
using namespace std;

//-------------------------------------------------------------- Solution 1

// vector<int> findErrorNums(vector<int>& nums) {
// vector<int> arr(nums.size() + 1, 0);
// vector<int> res(2,0);

// for(auto it: nums) {
// arr[it]++;
// }

// for(auto it = arr.begin() + 1; it != arr.end(); it++) {
// if(*it == 2) {
// res[0] = it - arr.begin();
// }
// if(*it == 0) {
// res[1] = it - arr.begin();
// }
// }

// return res;
// }

//-------------------------------------------------------------- Solution 2
vector<int> findErrorNums(vector<int>& nums) {
int len = nums.size();
int sum = ((len) * (len + 1)) / 2,
sum_sq = (len * (len + 1) * (2*len + 1) ) / 6;
vector<int> res(2,0);

for(auto it: nums) {
sum -= it;
sum_sq -= it*it;
}

res[1] = (sum_sq/sum + sum) / 2;
res[0] = res[1] - sum;

return res;
}

int main() {
vector<int> nums;
int x;

while(cin>>x){
nums.push_back(x);
}

vector<int> res;

res = findErrorNums(nums);

for(auto it: res) {
cout<<it<<",";
}

return 0;
}
18 changes: 18 additions & 0 deletions rerctangle_pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<iostream>

using namespace std;

int main() {
int row, cols;

cin>>row>>cols;

for(int i = 0; i < row; i++) {
for(int j = 0; j < cols; j++){
cout<<'*';
}
cout<<endl;
}

return 0;
}

0 comments on commit 07fc555

Please sign in to comment.