Skip to content

Commit 0b9fd0a

Browse files
committed
Add new Sol
1 parent 40923ed commit 0b9fd0a

File tree

19 files changed

+315
-0
lines changed

19 files changed

+315
-0
lines changed

CodeChef/MARCHB/1.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
#include <bits/stdc++.h>
3+
#include <cstdio>
4+
#include <cstring>
5+
#include <cmath>
6+
#include <cstring>
7+
#include <chrono>
8+
#include <complex>
9+
#define endl "\n"
10+
#define ll long long int
11+
#define vi vector<int>
12+
#define vll vector<ll>
13+
#define vvi vector < vi >
14+
#define pii pair<int,int>
15+
#define pll pair<long long, long long>
16+
#define mod 1000000007
17+
#define inf 1000000000000000001;
18+
#define all(c) c.begin(),c.end()
19+
#define mp(x,y) make_pair(x,y)
20+
#define mem(a,val) memset(a,val,sizeof(a))
21+
#define eb emplace_back
22+
#define f first
23+
#define s second
24+
25+
using namespace std;
26+
int main()
27+
{
28+
std::ios::sync_with_stdio(false);
29+
int T;
30+
cin>>T;
31+
// cin.ignore(); must be there when using getline(cin, s)
32+
while(T--)
33+
{
34+
int n,m;
35+
cin>>n>>m;
36+
37+
int arr[n], arr1[n];
38+
39+
std::map<int, int> m;
40+
for(int i = 0; i < n; i++)
41+
cin>>arr[i];
42+
43+
for(i)
44+
45+
46+
47+
48+
}
49+
return 0;
50+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
int matrixElementsSum(std::vector<std::vector<int>> matrix) {
2+
int sum = 0;
3+
4+
for(int i=0 ;i<matrix.size()-1;i++){
5+
for(int j = 0 ;j<matrix[i].size();j++){
6+
7+
8+
if(matrix[i][j]==0){
9+
matrix[i+1][j]=0;
10+
}
11+
}
12+
}
13+
14+
for(int i=0 ;i<matrix.size();i++){
15+
for(auto x : matrix[i]){
16+
if(x!=0)
17+
sum+=x;
18+
}
19+
}
20+
21+
22+
return sum ;
23+
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int firstDuplicate(std::vector<int> a) {
2+
map<int, int> mp;
3+
map<int,int>::iterator it;
4+
for(int i = 0; i < a.size(); i++){
5+
it = mp.find(a[i]);
6+
if(it != mp.end()){
7+
return a[i];
8+
}
9+
else
10+
mp.emplace(a[i],1);
11+
}
12+
return -1;
13+
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int firstDuplicate(std::vector<int> a) {
2+
map<int, int> mp;
3+
map<int,int>::iterator it;
4+
for(int i = 0; i < a.size(); i++){
5+
it = mp.find(a[i]);
6+
if(it != mp.end()){
7+
return a[i];
8+
}
9+
else
10+
mp.emplace(a[i],1);
11+
}
12+
return -1;
13+
14+
15+
}

Language/Java/Book.class

1.01 KB
Binary file not shown.

Language/Java/Employee.class

334 Bytes
Binary file not shown.

Language/Java/Exp2.class

1.34 KB
Binary file not shown.

Language/Java/Exp2.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.io.*;
2+
3+
class Employee implements Serializable{
4+
public int id;
5+
public String name;
6+
7+
public Employee(int id, String name){
8+
this.id = id;
9+
this.name = name;
10+
}
11+
}
12+
13+
public class Exp2{
14+
public static void main(String[] args) {
15+
try{
16+
17+
Employee e1 = new Employee(1, "Vedant");
18+
19+
FileOutputStream file = new FileOutputStream("output.ser");
20+
ObjectOutputStream out = new ObjectOutputStream(file);
21+
22+
out.writeObject(e1);
23+
24+
out.close();
25+
file.close();
26+
27+
System.out.println("Object has been serialized");
28+
29+
} catch(IOException ex){
30+
System.out.println("Io Occured");
31+
}
32+
33+
try{
34+
FileInputStream file = new FileInputStream("output.ser");
35+
ObjectInputStream in = new ObjectInputStream(file);
36+
37+
Employee e2 = null;
38+
e2 = (Employee)in.readObject();
39+
40+
in.close();
41+
file.close();
42+
43+
System.out.println("Object Deserialized");
44+
45+
System.out.println(e2.id);
46+
System.out.println(e2.name);
47+
}
48+
catch(IOException ex){
49+
System.out.println("IOExp caught");
50+
}
51+
catch(ClassNotFoundException ex){
52+
System.out.println("Class Not Fount Exp");
53+
54+
}
55+
}
56+
}

Language/Java/FileOp.class

1.78 KB
Binary file not shown.

Language/Java/FileOp.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class FileOp{
5+
public static void main(String[] args) {
6+
String str = "";
7+
//BufferedReader br = null;
8+
try{
9+
10+
LineNumberReader rd = new LineNumberReader(new InputStreamReader(new FileInputStream("file.txt"),"UTF-8"));
11+
12+
while(((str = rd.readLine()) != null) && rd.getLineNumber() < 5){
13+
System.out.println(str);
14+
}
15+
16+
rd.close();
17+
18+
}catch(FileNotFoundException e){
19+
System.err.println("File not found");
20+
}
21+
catch(IOException e){
22+
System.err.println("Unble to read the file");
23+
}
24+
25+
try{
26+
27+
String l_word="";
28+
String curr;
29+
30+
Scanner sc = new Scanner(new File("file.txt"));
31+
32+
while(sc.hasNext()){
33+
curr = sc.next();
34+
35+
if(curr.length() > l_word.length())
36+
l_word = curr;
37+
}
38+
39+
System.out.println("Longest Word: "+l_word);
40+
}catch(FileNotFoundException e){
41+
System.err.println("File not found");
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)