Skip to content

Commit aa2b3bd

Browse files
Mohit JainMohit Jain
Mohit Jain
authored and
Mohit Jain
committed
push latest code
1 parent 984a167 commit aa2b3bd

13 files changed

+240
-0
lines changed

.vscode/tasks.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: clang++ build active file",
6+
"command": "/usr/bin/clang++",
7+
"args": [
8+
"-fdiagnostics-color=always",
9+
"-g",
10+
"${file}",
11+
"-o",
12+
"${fileDirname}/${fileBasenameNoExtension}"
13+
],
14+
"options": {
15+
"cwd": "${fileDirname}"
16+
},
17+
"problemMatcher": [
18+
"$gcc"
19+
],
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
},
24+
"detail": "Task generated by Debugger."
25+
}
26+
],
27+
"version": "2.0.0"
28+
}

covid-pandemic

39 KB
Binary file not shown.

covid-pandemic.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
using namespace std;
33

44
int main() {
5+
6+
#ifndef ONLINE_JUDGE
7+
// for getting input from input.txt
8+
freopen("input.txt", "r", stdin);
9+
// for writing output to output.txt
10+
freopen("output.txt", "w", stdout);
11+
#endif
512
int t,count1,n,num,count0;
613
bool flag;
714
cin>>t;

hash-code.cpp

Whitespace-only changes.

input.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
92 022
3+
82 12
4+
77 13
5+
2 false numeric

maxSubArraySum

35.4 KB
Binary file not shown.

maxSubArraySum.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
#include<bits/stdc++.h>
3+
4+
using namespace std;
5+
6+
int main() {
7+
int t;
8+
cin>>t;
9+
while(t--){
10+
int n;
11+
cin>>n;
12+
int *a = new int[n];
13+
for(int i=0;i<n;i++) {
14+
cin>>a[i];
15+
}
16+
int ans = INT_MIN;
17+
int maxSumSoFar = 0;
18+
19+
for(int i=0; i <n;i++) {
20+
maxSumSoFar += a[i];
21+
if(maxSumSoFar<0){
22+
maxSumSoFar = 0;
23+
}
24+
if(maxSumSoFar>ans ){
25+
ans = maxSumSoFar;
26+
}
27+
28+
}
29+
cout<<ans<<endl;
30+
}
31+
return 0;
32+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.apple.xcode.dsym.maxSubArraySum</string>
9+
<key>CFBundleInfoDictionaryVersion</key>
10+
<string>6.0</string>
11+
<key>CFBundlePackageType</key>
12+
<string>dSYM</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
</dict>
20+
</plist>
Binary file not shown.

output.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
82 12
2+
77 13
3+
92 022

sortTheString

69.4 KB
Binary file not shown.

sortTheString.cpp

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <iostream>
2+
#include <cstring>
3+
#include <algorithm>
4+
5+
6+
using namespace std;
7+
8+
9+
string extractStringAtKey(string str, int key) {
10+
11+
char *s = strtok((char*)str.c_str()," ");
12+
13+
while(key>1) {
14+
s = strtok(NULL, " ");
15+
key--;
16+
17+
}
18+
return (string)s;
19+
}
20+
21+
int convertToInt(string s){
22+
int ans = 0;
23+
int p =1;
24+
for(int i = s.length()-1;i >=0;i--) {
25+
ans += ((s[i]-'0') *p);
26+
// ans += (stoi(s[i])*p);
27+
// ans += (atoi(s[i])*p);
28+
p = p*10;
29+
}
30+
return ans;
31+
}
32+
33+
bool numericCompare(pair<string,string> s1, pair<string,string> s2) {
34+
string key1 = s1.second;
35+
string key2 = s2.second;
36+
37+
return convertToInt(key1) < convertToInt(key2) ;
38+
}
39+
bool lexicoCompare(pair<string,string> s1, pair<string,string> s2) {
40+
string key1 = s1.second;
41+
string key2 = s2.second;
42+
43+
return key1 < key2 ;
44+
}
45+
int main() {
46+
47+
#ifndef ONLINE_JUDGE
48+
// for getting input from input.txt
49+
freopen("input.txt", "r", stdin);
50+
// for writing output to output.txt
51+
freopen("output.txt", "w", stdout);
52+
#endif
53+
54+
int n;
55+
cin>>n;
56+
57+
cin.get();
58+
59+
string a[100];
60+
61+
for(int i= 0; i < n; i++) getline(cin,a[i]);
62+
63+
int key;
64+
65+
66+
67+
68+
69+
string reversal, ordering;
70+
cin>>key>>reversal>>ordering;
71+
72+
73+
pair<string,string> strPair[100];
74+
75+
for(int i=0;i<n;i++){
76+
strPair[i].first = a[i];
77+
strPair[i].second = extractStringAtKey(a[i],key);
78+
}
79+
if(ordering == "numeric"){
80+
sort(strPair,strPair+n,numericCompare);
81+
} else {
82+
sort(strPair,strPair+n,lexicoCompare);
83+
}
84+
if(reversal == "true") {
85+
for(int i=0; i<n/2;i++) {
86+
swap(strPair[i],strPair[n-i-1]);
87+
}
88+
}
89+
90+
91+
92+
for(int i=0;i<n;i++) {
93+
cout<<strPair[i].first<<endl ;
94+
}
95+
96+
return 0;
97+
}
98+

wavePrint.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Take as input a two-d array. Wave print it column-wise.
2+
3+
// Input Format
4+
// Two integers M(row) and N(colomn) and further M * N integers(2-d array numbers).
5+
6+
// Constraints
7+
// Both M and N are between 1 to 10.
8+
9+
// Output Format
10+
// All M * N integers seperated by commas with 'END' wriiten in the end(as shown in example).
11+
12+
// Sample Input
13+
// 4 4
14+
// 11 12 13 14
15+
// 21 22 23 24
16+
// 31 32 33 34
17+
// 41 42 43 44
18+
// Sample Output
19+
// 11, 21, 31, 41, 42, 32, 22, 12, 13, 23, 33, 43, 44, 34, 24, 14
20+
#include<bits/stdc++.h>
21+
22+
using namespace std;
23+
24+
int main() {
25+
int m,n;
26+
cin>>m>>n;
27+
int **a = new int*[m];
28+
for(int i=0;i<m;i++){
29+
a[i] = new int[n];
30+
}
31+
for(int i=0;i<m;i++){
32+
for(int j=0;j<n;j++){
33+
cin>>a[i][j];
34+
}
35+
}
36+
for(int j=0;j<n;j++){
37+
if(j%2==0){
38+
for(int i=0;i<m;i++) cout<<a[i][j]<<", ";
39+
}else{
40+
for(int i=m-1;i>=0;i--) cout<<a[i][j]<<", ";
41+
42+
}
43+
}
44+
cout<<"END";
45+
return 0;
46+
47+
}

0 commit comments

Comments
 (0)