Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f6896e3
Adding first program
karthickk17 Dec 1, 2023
c395008
Merge branch 'SVCE-ACM:master' into master
karthickk17 Dec 2, 2023
9e1ccb5
Delete December 02 /.gitignore
karthickk17 Dec 2, 2023
5a4504c
Adding second program.
karthickk17 Dec 2, 2023
ff8be8e
Small edit
karthickk17 Dec 2, 2023
51cc4fc
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 3, 2023
1d6be61
Adding third program
karthickk17 Dec 3, 2023
75ee2c4
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 4, 2023
1867d44
Adding fourth program
karthickk17 Dec 4, 2023
91cbed0
Adding comment
karthickk17 Dec 4, 2023
de78986
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 5, 2023
6e39cd0
Adding fifth program
karthickk17 Dec 5, 2023
508e767
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 6, 2023
e250e55
Adding sixth program
karthickk17 Dec 6, 2023
9e48925
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 7, 2023
c63eea3
Adding seventh program
karthickk17 Dec 7, 2023
751beb2
Adding comment
karthickk17 Dec 7, 2023
36f27be
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 8, 2023
32dafab
Adding eigth program
karthickk17 Dec 8, 2023
da27f37
Adding eighth program
karthickk17 Dec 8, 2023
fb33e83
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 9, 2023
257b833
Adding ninth program
karthickk17 Dec 9, 2023
729b817
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 10, 2023
11b352c
Adding tenth program
karthickk17 Dec 10, 2023
51e8fa7
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 11, 2023
74b0f0f
adding eleventh program
karthickk17 Dec 11, 2023
a8ed523
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 12, 2023
218c9c5
Adding twelfth program
karthickk17 Dec 12, 2023
ada820f
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 13, 2023
47c59ed
adding thirteenth program
karthickk17 Dec 13, 2023
09b5e83
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 14, 2023
da72950
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 15, 2023
cb91e00
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 17, 2023
80a82fc
Adding program
karthickk17 Dec 20, 2023
7e87882
change comment
karthickk17 Dec 20, 2023
2c64c5b
change comment
karthickk17 Dec 20, 2023
74e6893
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 21, 2023
01f11f0
adding program
karthickk17 Dec 21, 2023
ebad481
adding program
karthickk17 Dec 22, 2023
e7d7f47
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 23, 2023
98b52e7
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 25, 2023
15ae8de
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 27, 2023
2e3f49b
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 29, 2023
2be48b1
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 30, 2023
61922e6
Merge remote-tracking branch 'upstream/master'
karthickk17 Dec 31, 2023
e883fc2
Adding program
karthickk17 Dec 31, 2023
6ca5958
Adding program
karthickk17 Dec 31, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
*.txt
2 changes: 2 additions & 0 deletions December 01/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

.vscode
15 changes: 15 additions & 0 deletions December 01/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin>>n;
vector<int> arr(n);
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<accumulate(arr.begin(),arr.end(),0)<<endl; //the third argument provides the initial sum
cout<<(max_element(arr.begin(),arr.end()) - arr.begin())<<endl; //max_element returns an iterator pointing to the maximum element.
//By subtracting with the first element iterator we get the index.
return 0;
}
2 changes: 2 additions & 0 deletions December 02/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

.vscode
23 changes: 23 additions & 0 deletions December 02/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin>>n;
vector<int> arr(n);
unordered_map<int,int> count;
for(int i=0;i<n;i++) {
cin>>arr[i];
count[arr[i]]++;
}
for(int i:arr){
if(count[i] > 0) {
cout<<count[i]<<" ";
//inorder to preserve the order of appearance of elements, I have to mark the
//visited elements by making their count as 0.
count[i] = 0;
}
}
return 0;
}
28 changes: 28 additions & 0 deletions December 03/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin>>n;
vector<int> arr(n);
int count = 1, max;
for (int i = 0; i < n; i++)
{
cin>>arr[i];

if(i == 0)
max = arr[i];
//Assigning the default value of the max as the first element.
//It can also be assigned as INT_MIN. It doesn't change the result.
else{

if(max<arr[i]){
count++;
max=arr[i];
}
}
}
cout<<count<<endl;
return 0;
}
25 changes: 25 additions & 0 deletions December 04/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
string str;
cin>>str;
int n = str.length();
if(n == 1) cout<<"Error";
//The smallest substing is of length 2 or 3. Its 2 in case of even length string and 3 in case of odd length string.
//All palindromic strings must have the same substring at the middle part. If it doesn't, it is not a palindrome.
else if(n % 2 == 0){
if(tolower(str[n/2]) == tolower(str[(n/2)-1]))
cout<<str.substr((n/2)-1,2);
else
cout<<"Error"<<endl;
}
else{
if(tolower(str[(n/2)-1])==tolower(str[(n/2)+1]))
cout<<str.substr((n/2)-1,3);
else
cout<<"Error"<<endl;
}
return 0;
}
19 changes: 19 additions & 0 deletions December 05/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin>>n;
vector<int> arr(n);
int avg;
for (int i = 0; i < n; i++)
cin>>arr[i];
//The test cases don't provide correct answer for the given question. In the first test case
//the average is 30 and the sum of elements greater than or equal to average are 30 40 and 50 whose sum is 120.
avg=accumulate(arr.begin(),arr.end(),0)/n;
sort(arr.begin(),arr.end());
cout<<accumulate(lower_bound(arr.begin(),arr.end(),avg),arr.end(),0)<<endl;//The lower_bound() returns the iterator that
//points to the first element greater or equal to the value provided.
return 0;
}
61 changes: 61 additions & 0 deletions December 06/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <bits/stdc++.h>

using namespace std;

vector<string> fin;//To store the final string array
int maxlen = 0;//To store the current maximum optimal array

void helper(int tempSize,string prev, vector<string> arr, vector<string> temp) {

if(tempSize>maxlen){
fin=temp;
maxlen=tempSize;
}
for(size_t i=0; i < arr.size(); i++) {
if(tempSize == 0){//It takes care of the initial cases. It ensures every string is started at least once.
string tempStore=arr[i];
temp.push_back(tempStore);
arr[i]="-1";
helper(tempSize+1,tempStore,arr,temp);
arr[i]=tempStore;
temp.pop_back();

}
else if(arr[i] != "-1") {
int count = 0;
for (int j = 0; j < prev.length(); j++) {
if(prev[j] != arr[i][j])
count++;
}
if(count <= 1) {//If the count is 1, then the string has only one difference with the previous one
string tempStore=arr[i];
arr[i] = "-1";
temp.push_back(tempStore);
helper(tempSize+1,tempStore,arr,temp);//It uses a recursion technique to find all possible combinations
//Can use dp to optimize this better.
arr[i]=tempStore;
temp.pop_back();
}

}
}
}

int main() {
int n;
//cin>>n;
n=7;
vector<string> arr(n);
arr={"cat", "cot", "dot", "dog", "cog", "coat", "doll"};
// for(int i=0;i<n;i++)
// cin>>arr[i];
helper(0,"",arr, {});
if(fin.size() == 1)
cout<<"No valid chain";
else{
for(string t:fin)
cout<<t<<" ";
cout<<endl;
}
return 0;
}
11 changes: 11 additions & 0 deletions December 07/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int width,height,radius;
cin>>width>>height>>radius;
float diagonal = sqrt(pow(width,2)+pow(height,2));
cout<<boolalpha<<(ceil(diagonal)<=(2*radius));//boolalpha sets the flag to display the boolean values as true or false.
return 0;
}
45 changes: 45 additions & 0 deletions December 08/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <bits/stdc++.h>

using namespace std;
/*
The program works as follows:
First the numbers are placed increasingly like 1,2,3,...
1 is always placed at the first row and middle column.
for a 3x3 matrix, it is placed as
0 1 0
0 0 0
0 0 0
Then we go to north-east element of our position. For element 5, it is 3 and for element 8, it is 6.
1 2 3
4 5 6
7 8 9
If the element already contains a number, place the holding string directly below it.
If the positions go beyond the boundaries of the matrix, rotate it appropriately such that it comes within the range.
*/
int main() {
int n;
cin>>n;
vector<vector<int>> matrix(n, vector<int>(n,0));
int r=0, c=(n/2), cur_num=1;
while(cur_num <= n*n) {
matrix[r][c] = cur_num;
cur_num++;
c=(c+1)%n;
r=r-1;
if(r<0) r=n-1;
if(matrix[r][c] != 0) {
c-=1;
if(c<0) c=n-1;
r=(r+2)%n;
}
}
int maxDigits = to_string(n*n).length();//n*n is the maximum number in the matrix
for (vector<int> arr : matrix) {
for (int num : arr) {
// Displaying the number with proper spacing.
cout << setw(maxDigits) << num << " ";
}
cout << endl;
}
return 0;
}
16 changes: 16 additions & 0 deletions December 09/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int no_words = 1;//The first word doesn't have uppercase letters
//Every uppercase character marks the beginning of new word.
string line;
cin>>line;
for(char ch:line) {
if(ch >= 'A' && ch <= 'Z')
no_words++;
}
cout<<no_words<<endl;
return 0;
}
38 changes: 38 additions & 0 deletions December 10/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
set<string> tables{"emp"};//It is used for storing table names
unordered_map<string, vector<string>> table_column_map{{"emp",{"empname"}}};//It is used for storing the list of columns for the given table
unordered_map<string, vector<string>> column_values{{"empname",{"Shivnash Kumar", "Ragul Gupta"}}};//It is used for storing the list of columns for the given table
string query, tableName, columnName;
int length, startIndex;
getline(cin, query);
//query = "select substring(empname,4,13) from emp;";
transform(query.begin(),query.end(),query.begin(),::tolower);
regex pattern(R"(select\s+substring\((\w+),(\d+),(\d+)\)\s+from\s+(\w+);)");

// Match the regular expression pattern against the query
smatch matches;
if (regex_match(query, matches, pattern)) {
// Extract the matched components
columnName = matches[1].str();
startIndex = stoi(matches[2].str())-1; // Convert to int
length = stoi(matches[3].str()); // Convert to int
tableName = matches[4].str();
}
else {
cout << "Invalid query format." << endl;
}
if(tables.find(tableName) == tables.end()) cout<<"Invalid Table Name";
auto it = table_column_map.find(tableName);
if (it == table_column_map.end() || find(it->second.begin(), it->second.end(), columnName) == it->second.end()) {
cout << "Column is not present in the table." << endl;
}
it = column_values.find(columnName);
for(string str: it->second) {
cout<<str.substr(startIndex, length)<<endl;
}
return 0;
}
25 changes: 25 additions & 0 deletions December 11/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

using namespace std;

void add_and_convert(int num1, int num2) {
int sum = num1 + num2;
string ans = "";
while (sum > 0) {
if (sum & 1) //In the bit representation, if the bit is set as 1, the string is appended with 1
ans += "1";
else
ans += "0";
sum >>= 1;
}
//As the bits are checked from left to right, we have to reverse finally to display in properly.
reverse(ans.begin(), ans.end());
cout<<ans;
}

int main() {
int num1, num2;
cin >> num1 >> num2;
add_and_convert(num1, num2);
return 0;
}
47 changes: 47 additions & 0 deletions December 12/cpp_karthickk17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool binarySearch(vector<string> box, string target) {
int low = 0;
int high = box.size() - 1;

while (low <= high) {
int mid = low + (high - low) / 2;

if (box[mid] == target) {
return true; // Gold found in this box
} else if (box[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}

return false; // Gold not found in this box
}

string findGoldBox(vector<vector<string>> boxes) {
for (auto box = boxes.begin(); box != boxes.end(); box++) {
sort(box->begin(), box->end()); //Sorting the items based on the alphabetical order.
if (binarySearch(*box, "Gold"))
return {"Box"+to_string(box-boxes.begin()+1)+" contains the Gold"};//To display the position of the box
}

return "Gold not found in any box"; // This should not happen if the input is valid
}

int main() {

vector<vector<string>> boxes = {
{"Emerald", "Ruby", "Bronze", "Silver"},
{"Gold", "Diamond", "Ruby", "Copper"},
{"Ruby", "Platinum", "Bronze", "Silver"}
};

cout << findGoldBox(boxes) << endl;

return 0;
}
Loading