Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 69044f9

Browse files
committed
Merge branch 'master' of https://github.com/javaarchive/Java
2 parents dab7eed + c66a54e commit 69044f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6709
-1
lines changed
3.72 KB
Binary file not shown.

Code-Forces/bin/cat_party.class

1.68 KB
Binary file not shown.
2.72 KB
Binary file not shown.
890 Bytes
Binary file not shown.
1.92 KB
Binary file not shown.

Code-Forces/src/StoTConverter.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.util.*;
2+
import java.util.stream.Collectors;
3+
public class StoTConverter {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
int N = sc.nextInt();sc.nextLine();
7+
for(int run = 0; run < N; run++) {
8+
9+
String s = sc.nextLine(),t = sc.nextLine(),p = sc.nextLine();
10+
ArrayList<Character> needed = new ArrayList<Character>();
11+
System.out.println("s:"+s+"\n"+"t:"+t+"\n"+"p:"+p);
12+
try {
13+
int min = Integer.min(s.length(),t.length());
14+
for(int i = 0; i < min; i ++) {
15+
if(!(s.charAt(i) == t.charAt(i))) {
16+
throw new Exception("SOLUTION REQUIRES REORDER");
17+
}
18+
}
19+
for(int i =0 ; i < t.length(); i ++) {
20+
//System.out.println("add "+i);
21+
needed.add(t.charAt(i));
22+
}
23+
System.out.println("End Result: "+needed);
24+
for(int i =0 ; i < s.length(); i ++) {
25+
needed.remove(needed.indexOf(s.charAt(i)));
26+
}
27+
System.out.println("Letters needed: "+needed);
28+
29+
List<Character> chars = p.chars() // IntStream
30+
.mapToObj(e -> (char)e) // Stream<Character>
31+
.collect(Collectors.toList());
32+
//System.out.println("Letters to find: "+needed);
33+
System.out.println("Letters to be used before: "+chars);
34+
for(char c: needed) {
35+
//chars.remove(Character.valueOf(c));
36+
chars.remove(chars.indexOf(c));
37+
}
38+
System.out.println("Letters to be used after: "+chars);
39+
System.out.println("YES");
40+
}catch(Exception e) {
41+
System.out.println("NO "+e.getLocalizedMessage());
42+
}
43+
44+
}
45+
}
46+
}

Code-Forces/src/cat_party.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
public class cat_party {
3+
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
int N = sc.nextInt();
7+
int[] days = new int[N];
8+
for(int i = 0; i < N; i ++) {
9+
days[i] = sc.nextInt();
10+
}
11+
12+
HashMap<Integer,Integer> freq = new HashMap<Integer,Integer>();
13+
int out = N;
14+
for(int i = 0; i < N; i ++) {
15+
freq.putIfAbsent(days[i], 0);
16+
freq.put(days[i],freq.get(days[i])+1);
17+
//System.out.println(freq);
18+
Set<Integer> values = new HashSet<Integer>(freq.values());
19+
//System.out.println("Map "+values.size()+" i = "+i+" "+values);
20+
if(values.size() == 2) {
21+
//System.out.println("Day "+i);
22+
out = i + 1;
23+
}
24+
}
25+
Set<Integer> values = new HashSet<Integer>(freq.values());
26+
//System.out.println("Map "+values.size()+" i = "+N+" "+values);
27+
28+
//System.out.println(freq);
29+
System.out.println(out);
30+
sc.close();
31+
}
32+
33+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
5+
public class japanese_majhong {
6+
static List<Integer> m,p,s;
7+
public static int maxConsect;
8+
public static int maxSame;
9+
public static int consect_count;
10+
public static int same_count;
11+
public static void process(List<Integer> l){
12+
maxConsect = 0;
13+
maxSame = 0;
14+
consect_count = 0;
15+
same_count = 0;
16+
boolean isConsecutive = false;
17+
boolean isSame = false;
18+
int prev = -1;
19+
for(int num:l) {
20+
if(isConsecutive == false && isSame == false) {
21+
isConsecutive = true;
22+
isSame = true;
23+
consect_count ++;
24+
same_count ++;
25+
}else {
26+
if(prev == (num - 1)) {
27+
isConsecutive = true;
28+
}else if(prev == num) {
29+
isSame = true;
30+
}
31+
if(isConsecutive) {
32+
if(prev == (num - 1)) {
33+
isConsecutive = true;
34+
consect_count++;
35+
}else {
36+
isConsecutive = false;
37+
}
38+
}
39+
if(isSame) {
40+
if(prev == num) {
41+
isSame = true;
42+
same_count++;
43+
}
44+
}else{
45+
isSame = false;
46+
}
47+
48+
}
49+
if(same_count > maxSame){
50+
maxSame = same_count;
51+
}
52+
if(consect_count > maxConsect) {
53+
maxConsect = consect_count;
54+
}
55+
prev = num; // Keep at end
56+
}
57+
}
58+
public static void main(String[] args) {
59+
Scanner sc = new Scanner(System.in);
60+
m = new ArrayList<Integer>();
61+
p = new ArrayList<Integer>();
62+
s = new ArrayList<Integer>();
63+
//System.out.println(s);
64+
for(int i = 0; i < 3; i ++) {
65+
String str = sc.next();
66+
String suit = str.substring(1);
67+
//System.out.println(suit);
68+
int num = Integer.parseInt(str.substring(0, 1));
69+
if(suit.equals("m")) {
70+
m.add(num);
71+
}else if(suit.equals("p")) {
72+
p.add(num);
73+
}else if(suit.equals("s")) {
74+
s.add(num);
75+
}
76+
}
77+
m.sort(null);
78+
p.sort(null);
79+
s.sort(null);
80+
int ans;
81+
int maxMaxSame = -1;
82+
int maxMaxConsect = -1;
83+
//System.out.println("m");
84+
process(m);
85+
maxMaxSame = maxSame;
86+
maxMaxConsect = maxConsect;
87+
//System.out.println(maxConsect+" "+maxSame);
88+
//System.out.println("p");
89+
process(p);
90+
maxMaxSame = Integer.max(maxSame, maxMaxSame);
91+
maxMaxConsect = Integer.max(maxConsect, maxMaxConsect);
92+
//System.out.println(maxConsect+" "+maxSame);
93+
//System.out.println("s");
94+
process(s);
95+
maxMaxSame = Integer.max(maxSame, maxMaxSame);
96+
maxMaxConsect = Integer.max(maxConsect, maxMaxConsect);
97+
//System.out.println(maxConsect+" "+maxSame);
98+
System.out.println(Integer.min(3 - maxMaxSame, 3 - maxMaxConsect));
99+
}
100+
101+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.*;
2+
public class programming_rewards {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
int x = sc.nextInt();
6+
int y = sc.nextInt();
7+
int z = sc.nextInt();
8+
if(x > y || x > z) {
9+
System.out.println("No");
10+
}else {
11+
System.out.println("Yes");
12+
}
13+
}
14+
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.*;
2+
3+
public class vus_cossack_strings {
4+
public static int diff(String m, String p) {
5+
int answer = 0;
6+
assert (m.length() == p.length());
7+
int N = m.length();
8+
for(int i = 0; i < N; i ++) {
9+
if(m.charAt(i) != p.charAt(i)) {
10+
answer ++;
11+
}
12+
}
13+
return answer;
14+
}
15+
public static void main(String[] args) {
16+
Scanner sc = new Scanner(System.in);
17+
String a = sc.nextLine();
18+
String b = sc.nextLine();
19+
sc.close();
20+
int lenA = a.length();
21+
int len = b.length();
22+
int count = 0;
23+
//List<String> substrings = new ArrayList<String>();
24+
/*
25+
for(int i = 0 ; i < lenA; i ++) {
26+
if(a.charAt(i) == 1) {
27+
28+
}else {
29+
// assert (a.charAt(i) == 0);
30+
}
31+
}
32+
*/
33+
int N = lenA - len + 1;
34+
for(int i = 0; i < N; i++) {
35+
//if(i + len > lenA) {
36+
// break;
37+
//}
38+
//substrings.add();
39+
System.out.println(i+"\n"+(i+len));
40+
if(diff(a.substring(i, i + len),b) % 2 == 0) {
41+
count++;
42+
}
43+
}
44+
45+
//System.out.println(substrings);
46+
47+
System.out.println(count);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)