Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5551867

Browse files
debug section, solved mostly all]
1 parent c8f5e01 commit 5551867

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

‎prime-date.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
import java.math.*;
5+
6+
public class Main {
7+
8+
public static int month[];
9+
10+
public static void main (String[] args) throws java.lang.Exception {
11+
Scanner in = new Scanner(System.in);
12+
13+
month = new int[15];
14+
15+
String s = in.nextLine();
16+
17+
StringTokenizer str = new StringTokenizer(s, "- ");
18+
19+
int d1 = Integer.parseInt(str.nextToken());
20+
int m1 = Integer.parseInt(str.nextToken());
21+
int y1 = Integer.parseInt(str.nextToken());
22+
int d2 = Integer.parseInt(str.nextToken());
23+
int m2 = Integer.parseInt(str.nextToken());
24+
int y2 = Integer.parseInt(str.nextToken());
25+
26+
int result = findPrimeDates(d1, m1, y1, d2, m2, y2);
27+
System.out.println(result);
28+
}
29+
30+
public static void updateLeapYear(int year) {
31+
if(year % 400 == 0) {
32+
month[2] = 29;
33+
} else if(year % 100 == 0) {
34+
month[2] = 28;
35+
} else if(year % 4 == 0) {
36+
month[2] = 29;
37+
} else {
38+
month[2] = 28;
39+
}
40+
}
41+
42+
public static void storeMonth() {
43+
month[1] = 31;
44+
month[2] = 28;
45+
month[3] = 31;
46+
month[4] = 30;
47+
month[5] = 31;
48+
month[6] = 30;
49+
month[7] = 31;
50+
month[8] = 31;
51+
month[9] = 30;
52+
month[10] = 31;
53+
month[11] = 30;
54+
month[12] = 31;
55+
}
56+
57+
public static int findPrimeDates(int d1, int m1, int y1, int d2, int m2, int y2) {
58+
storeMonth();
59+
60+
int result = 0;
61+
62+
while(true) {
63+
int x = d1;
64+
x = x * 100 + m1;
65+
x = x * 10000 + y1;
66+
if(x % 4 == 0 || x % 7 == 0) {
67+
result = result + 1;
68+
}
69+
if(d1 == d2 && m1 == m2 && y1 == y2) {
70+
break;
71+
}
72+
updateLeapYear(y1);
73+
d1 = d1 + 1;
74+
if(d1 > month[m1]) {
75+
m1 = m1 + 1;
76+
d1 = 1;
77+
if(m1 > 12) {
78+
y1 = y1 + 1;
79+
m1 = 1;
80+
}
81+
}
82+
}
83+
return result;
84+
}
85+
}

‎smart-number.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import math
2+
3+
def is_smart_number(num):
4+
val = int(math.sqrt(num))
5+
if num / val == val:
6+
return True
7+
return False
8+
9+
for _ in range(int(input())):
10+
num = int(input())
11+
ans = is_smart_number(num)
12+
if ans:
13+
print("YES")
14+
else:
15+
print("NO")

‎strings-xor.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Solution {
8+
9+
public static String stringsXOR(String s, String t) {
10+
String res = new String("");
11+
for(int i = 0; i < s.length(); i++) {
12+
if(s.charAt(i) == t.charAt(i))
13+
res += "0";
14+
else
15+
res += "1";
16+
}
17+
18+
return res;
19+
}
20+
21+
public static void main(String[] args) {
22+
23+
String s, t;
24+
Scanner in = new Scanner(System.in);
25+
s = in.nextLine();
26+
t = in.nextLine();
27+
System.out.println(stringsXOR(s, t));
28+
29+
}
30+
31+
}
32+
33+
34+

‎zig-zag-sequence.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
import java.math.*;
5+
public class Main {
6+
7+
public static void main (String[] args) throws java.lang.Exception {
8+
Scanner kb = new Scanner(System.in);
9+
int test_cases = kb.nextInt();
10+
for(int cs = 1; cs <= test_cases; cs++){
11+
int n = kb.nextInt();
12+
int a[] = new int[n];
13+
for(int i = 0; i < n; i++){
14+
a[i] = kb.nextInt();
15+
}
16+
findZigZagSequence(a, n);
17+
}
18+
}
19+
20+
public static void findZigZagSequence(int [] a, int n){
21+
Arrays.sort(a);
22+
int mid = n / 2;
23+
int temp = a[mid];
24+
a[mid] = a[n - 1];
25+
a[n - 1] = temp;
26+
27+
int st = mid + 1;
28+
int ed = n - 2;
29+
while(st <= ed){
30+
temp = a[st];
31+
a[st] = a[ed];
32+
a[ed] = temp;
33+
st = st + 1;
34+
ed = ed - 1;
35+
}
36+
for(int i = 0; i < n; i++){
37+
if(i > 0) System.out.print(" ");
38+
System.out.print(a[i]);
39+
}
40+
System.out.println();
41+
}
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /