Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3830de9

Browse files
committed
New solutions for some files in Java & Python
1 parent 51bf474 commit 3830de9

File tree

80 files changed

+2307
-109
lines changed

Some content is hidden

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

80 files changed

+2307
-109
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
import java.util.Scanner;
4+
5+
public class Test {
6+
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
int W = sc.nextInt();
10+
int N = sc.nextInt();
11+
int area=0;
12+
for (int i = 0; i < N; i++) {
13+
area+= sc.nextInt() * sc.nextInt();
14+
}
15+
System.out.println(area/W);
16+
17+
}
18+
}
19+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
import java.util.Scanner;
4+
public class Test {
5+
public static void main(String[] args) {
6+
7+
Scanner sc = new Scanner(System.in);
8+
List<String> orginal = new ArrayList<String>();
9+
List<String> arr = new ArrayList<String>();
10+
String str = "";
11+
int n = 0;
12+
13+
orginal.add(0, "shanbe");
14+
for(int i=1; i<6; i++)
15+
orginal.add(i, i+"shanbe");
16+
orginal.add(6, "jome");
17+
18+
19+
int one = sc.nextInt();
20+
for(int i=0; i<one; i++){
21+
str = sc.next();
22+
arr.add(str);
23+
}
24+
25+
int two = sc.nextInt();
26+
for(int i=0; i<two; i++){
27+
str = sc.next();
28+
arr.add(str);
29+
}
30+
31+
int three = sc.nextInt();
32+
for(int i=0; i<three; i++){
33+
str = sc.next();
34+
arr.add(str);
35+
}
36+
37+
for(int i=0; i<orginal.size(); i++){
38+
for(int j=0; j<arr.size(); j++){
39+
if(orginal.get(i).equals(arr.get(j)))
40+
break;
41+
if(j==arr.size()-1)
42+
if(!orginal.get(i).equals(arr.get(j)))
43+
n += 1;
44+
}
45+
}
46+
System.out.println(n);
47+
}
48+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
import java.util.Scanner;
4+
5+
6+
/**
7+
* @Author: Mohammadyar Barandov
8+
*
9+
*/
10+
11+
public class Test {
12+
13+
public static void main(String[] args) {
14+
Scanner sc = new Scanner(System.in);
15+
int n = sc.nextInt() , m=sc.nextInt();
16+
int stars=0;
17+
String sky = new String("");
18+
for (int i = 0; i < n; i++) {
19+
sky = sc.next();
20+
for (int j = 0; j < m; j++) {
21+
if (sky.charAt(j) == '*')
22+
stars++;
23+
}
24+
}
25+
System.out.println(stars);
26+
sc.close();
27+
}
28+
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Scanner;
2+
3+
public class Test {
4+
5+
public static Scanner console = new Scanner(System.in);
6+
7+
public static void main(String[] args) {
8+
boolean[] ADays = new boolean[31];
9+
boolean[] BDays = new boolean[31];
10+
11+
int ADaysCnt = console.nextInt();
12+
int BDaysCnt = console.nextInt();
13+
14+
for (int i = 1; i <= ADaysCnt; i++) {
15+
int start = console.nextInt();
16+
int end = console.nextInt();
17+
18+
for (int index = start; index <= end; index++)
19+
ADays[index] = true;
20+
}
21+
22+
for (int i = 1; i <= BDaysCnt; i++) {
23+
int start = console.nextInt();
24+
int end = console.nextInt();
25+
26+
for (int index = start; index <= end; index++)
27+
BDays[index] = true;
28+
}
29+
30+
int possibleDaysCnt = 0;
31+
for (int day = 1; day < 31; day++) {
32+
if (ADays[day] && BDays[day])
33+
possibleDaysCnt++;
34+
}
35+
36+
System.out.println(possibleDaysCnt);
37+
}
38+
}
39+
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
12
import java.util.Scanner;
2-
3+
34
public class Main {
4-
static Scanner sc = new Scanner(System.in);
5+
56
public static void main(String[] args) {
6-
int num = sc.nextInt();
7-
String currentName;
8-
int tempCount=0;
9-
int counter=0;
10-
int maxCounter=0;
11-
int tempLength=0;
12-
char[] ch = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' ,'z'};
13-
for (int i=0; i<=num; i++)
14-
{
15-
currentName = sc.nextLine();
16-
tempLength = currentName.length();
17-
for(int j=0; j<=25;j++)
18-
{
19-
tempCount = currentName.replace(String.valueOf(ch[j]), "").length();
20-
if(tempCount==tempLength)
21-
continue;
22-
counter++;
23-
tempCount=0;
7+
8+
// Better Solution
9+
10+
Scanner sc = new Scanner(System.in);
11+
12+
int n = sc.nextInt();
13+
String names;
14+
15+
int [] number = new int[n];
16+
for (int i = 0; i < n; i++) {
17+
int count=0;
18+
names = sc.next();
19+
char[] chars = names.toCharArray();
20+
for (int j = 0; j < names.length(); j++) {
21+
for (int k = j+1; k < names.length(); k++) {
22+
if (chars[j] == chars[k] && chars[j] !=' ') {
23+
count++;
24+
chars[k] = ' '; //Set chars[k] to ' ' to avoid printing visited character
25+
}
26+
}
2427
}
25-
if(counter>maxCounter)
26-
maxCounter = counter;
27-
counter=0;
28+
number[i] = names.length()-count;
2829
}
29-
System.out.println(maxCounter);
30+
int max = number[0];
31+
for (int i = 0; i < number.length; i++) {
32+
if (number[i] > max)
33+
max = number[i];
34+
}
35+
System.out.println(max);
36+
sc.close();
3037
}
31-
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import java.util.Scanner;
3+
4+
public class Test2 {
5+
6+
public static void main(String[] args) {
7+
Scanner sc = new Scanner(System.in);
8+
int n = sc.nextInt(), m = sc.nextInt();
9+
int [][] array = new int[n+1][n+1];
10+
int result = 0;
11+
12+
for (int i = 1; i <= n; i++) {
13+
for (int j = 1; j <= n; j++) {
14+
array[i][j] = sc.nextInt();
15+
}
16+
}
17+
18+
for (int i = 0; i < m; i++) {
19+
int x = sc.nextInt() , y = sc.nextInt();
20+
result += array[x][y];
21+
}
22+
23+
System.out.println(result);
24+
25+
sc.close();
26+
}
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def calculator(n, m, li):
2+
overall_l = []
3+
number_of_sub_lists = int((n / m) + (n % m))
4+
gp = 0
5+
counter = 0
6+
7+
for a in range(number_of_sub_lists): # Create m sub list in overall list
8+
lst = []
9+
overall_l.append(lst)
10+
11+
while counter + m <= n: # Filling sub lists
12+
for j in range(counter, counter + m):
13+
overall_l[gp].append(li[j])
14+
gp += 1
15+
counter += m
16+
17+
for k in range(counter, n): # Adding remaining of original list to overall list
18+
overall_l[gp].append(li[k])
19+
20+
sum_of_overall_l = []
21+
for item in range(len(overall_l)): # Calculate sum of each list and add to new list
22+
sum_of_overall_l.append(sum(overall_l[item]))
23+
24+
temp = sum_of_overall_l[0]
25+
step = 1
26+
for z in range(len(sum_of_overall_l)):
27+
if (step + 1 <= len(sum_of_overall_l)) and (step % 2 != 0):
28+
temp -= sum_of_overall_l[step]
29+
step += 1
30+
elif (step + 1 <= len(sum_of_overall_l)) and (step % 2 == 0):
31+
temp += sum_of_overall_l[step]
32+
step += 1
33+
return temp
34+
35+
36+
# print(calculator(8, 3, [1, 2, 3, 4, 5, 6, 7, 8]))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Scanner;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
int user_input = sc.nextInt();
7+
String [] sofre = {"ib","amano","enjed","abze","aat","eke","erke","omaq","ir"};
8+
for (int i=0;i<user_input;i++){
9+
10+
System.out.println("s"+sofre[i]);
11+
12+
}
13+
}
14+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.util.Scanner;
2+
3+
public class Test4 {
4+
//
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
int n = sc.nextInt() , m = sc.nextInt();
8+
sc.nextLine();
9+
String[] str = new String[n];
10+
11+
for (int i = 0; i < n; i++) {
12+
13+
str[i] = sc.nextLine(); //getting strings
14+
15+
}
16+
17+
String s = sc.nextLine(); // getting desire string
18+
int size = s.length();
19+
int count = 0 , difference = 0;
20+
21+
for (int i = 0; i < n; i++) {
22+
for (int j = 0; j <= m - size; j++) {
23+
difference = 0;
24+
for (int k = 0; k <size ; k++) {
25+
if (s.charAt(k) != str[i].charAt(k+j))
26+
difference = 1;
27+
}
28+
if (difference == 0)
29+
count++;
30+
}
31+
}
32+
33+
34+
for (int i = 0; i <= n-size; i++) {
35+
for (int j = 0; j < m; j++) {
36+
difference = 0;
37+
for (int k = 0; k < size; k++) {
38+
if (s.charAt(k) != str[i+k].charAt(j))
39+
difference = 1;
40+
}
41+
if (difference == 0)
42+
count++;
43+
}
44+
45+
}
46+
47+
System.out.println(count);
48+
49+
50+
sc.close();
51+
}
52+
53+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*;
2+
3+
public class Test {
4+
5+
6+
public static void main(String[] args){
7+
8+
Scanner sc = new Scanner(System.in);
9+
int n = sc.nextInt() , x = sc.nextInt(), k = sc.nextInt();
10+
String[] channelNames = new String[n+1];
11+
int i=1;
12+
while(i<=n){
13+
channelNames[i] = sc.next();
14+
i++;
15+
}
16+
for(i=1;i<=k;i++){
17+
if (x < n)
18+
x = x + 1;
19+
else if (x == n)
20+
x = 1;
21+
22+
}
23+
System.out.println("\n"+channelNames[x]);
24+
sc.close();
25+
}
26+
27+
}

0 commit comments

Comments
 (0)