Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my contribution #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 1353A - Most Unstable Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
if n == 1:
print(0)
elif n == 2:
print(m)
else:
print(2 * m)
21 changes: 21 additions & 0 deletions 1676B - Equal Candies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;
public class Main{
public static void main(String [] lol){
Scanner scanner = new Scanner(System.in);
int t= scanner.nextInt();
for(int i=0;i<t;i++){
int n= scanner.nextInt(); // number of boxes
int [] candies = new int[n]; // input for arrays
for(int j=0;j<n;j++){
candies[j]= scanner.nextInt();
// read the input for the aarays
}
int minCandies= 0;
for (int candy: candies){ min=Math.min(minCandies,candy);}
int totalCandiesToEat =0;
for(int candy : candies){ totalCandiesToEat += candy - minCandies;}
System.out.println(totalCandiesToEat);
}
scanner.close();
}
}
8 changes: 8 additions & 0 deletions 1676B - Equal Candies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
t= int(intput())
for _ in range(t):
n = int(intput())
candies= list(map(int,input().split()))
min_candies= min(candies)
candies_to_eat= [c- min_candies for c in candies]
total_candies_to_eat= sum(candies_to_eat)
print(total_candies_to_eat)
29 changes: 29 additions & 0 deletions 1742B - Increasing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Scanner;
import java.util.HashSet;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();

for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int[] arr = new int[n];
for (int j = 0; j < n; j++) {arr[j] = scanner.nextInt();}
boolean isDistinct = isDistinct(arr);
if (isDistinct) {System.out.println("YES");
} else { System.out.println("NO");}
}
scanner.close();
}

private static boolean isDistinct(int[] arr) {
HashSet<Integer> set = new HashSet<>();
for (int num : arr) {
if (!set.add(num)) {
return false;
}
}
return true;
}
}
10 changes: 10 additions & 0 deletions 1742B - Increasing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
t = int(input()) # number of test cases

for _ in range(t):
n = int(input()) # length of the array
arr = list(map(int, input().split())) # elements of the array

if len(set(arr)) == n:
print("YES")
else:
print("NO")
40 changes: 40 additions & 0 deletions 1760A - Medium Number.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input the number of test cases
System.out.println("Enter the number of test cases:");
int t = scanner.nextInt();
scanner.nextLine(); // Consume newline character

for (int i = 0; i < t; i++) {
// Input the array elements
System.out.println("Enter elements of array " + (i + 1) + ":");
String[] input = scanner.nextLine().split(" ");
int[] arr = new int[input.length];

// Convert String array to integer array
for (int j = 0; j < input.length; j++) {
arr[j] = Integer.parseInt(input[j]);
}

// Find the maximum and minimum numbers in the array
int maxNum = Integer.MIN_VALUE;
int minNum = Integer.MAX_VALUE;
for (int num : arr) {
maxNum = Math.max(maxNum, num);
minNum = Math.min(minNum, num);
}

// Print the number that is neither maximum nor minimum
for (int num : arr) {
if (num != maxNum && num != minNum) {
System.out.println("Number that is neither maximum nor minimum: " + num);
break; // Exit the loop after finding the number
}
}
}
}
}
9 changes: 9 additions & 0 deletions 1760A - Medium Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
t = int(input())

for _ in range(t):
arr = list(map(int, input().split()))
max_num = max(arr)
min_num = min(arr)
for num in arr:
if num != max_num and num != min_num:
print(num)
17 changes: 17 additions & 0 deletions 1772A - A+B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Scanner;
public class Main{
public static void main(String [] lol){
Scanner scanner = new Scanner(System.in);
int t= scanner.nextInt();
scanner.nextLine(); // takes the input for equation
for ( int i =0 ;i< t ;i++){
String numbers= scanner.nextLine().split("\\+");
int a = Interger.parseInt(numbers[0]);
int b= Interger.parseInt(numbers[1]);

System.out.println(a+b);

}
scanner.close();
}
}
4 changes: 4 additions & 0 deletions 1772A - A+B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
t=int(input())
for _ in range(t):
a,b=map(int,input().split('+'))
print(a+b)
8 changes: 8 additions & 0 deletions 1873A - Short Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
t= int(input())
for _ in range(t):
str= str(input())
if str[0]=='a' or str[1]=='b' or str[2]=='c':
return 'Yes'
else:
return 'No'

17 changes: 17 additions & 0 deletions 1873A-Short Sort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < t; i++) {
String str = scanner.nextLine();
if (str.charAt(0) == 'a' || str.charAt(1) == 'b' || str.charAt(2) == 'c') {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
}
9 changes: 9 additions & 0 deletions 1926A - Vlad and the Best of Five.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
t= int(input())
for _ in range(t):
s= input()
count_a=s.count('A')
count_b=s.count('B')
if count_a < count_b:
print('B')
else:
print('A')
10 changes: 10 additions & 0 deletions 1950A - Stair, Peak, or Neither.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
t = int(input())
for _ in range(t):
a, b, c = map(int, input().split())

if a < b < c:
print('STAIR')
elif a < b > c:
print("PEAK")
else:
print("NONE")
28 changes: 28 additions & 0 deletions 381A - Sereja and Dima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
n = int(input())
arr = list(map(int, input().split()))

point1 = 0
point2 = 0

left = 0
right = n - 1

sereja_turn = True

while left <= right:
if sereja_turn:
point1 += max(arr[left], arr[right])
if arr[left] > arr[right]:
left += 1
else:
right -= 1
else:
point2 += max(arr[left], arr[right])
if arr[left] > arr[right]:
left += 1
else:
right -= 1

sereja_turn = not sereja_turn

print(point1, point2)
19 changes: 19 additions & 0 deletions 472A - Design Tutorial_ Learn from Math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def is_composite(num):
if num < 4:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return True
return False

def find_composite_pair(n):
for i in range(4, n):
if is_composite(i) and is_composite(n - i):
return i, n - i

# Input
n = int(input())

# Output
x, y = find_composite_pair(n)
print(x, y)
19 changes: 19 additions & 0 deletions 702A - Maximum Increase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def maximum_increase(n, arr):
max_length = 1
current_length = 1

for i in range(1, n):
if arr[i] > arr[i - 1]:
current_length += 1
max_length = max(max_length, current_length)
else:
current_length = 1

return max_length

# Input
n = int(input())
arr = list(map(int, input().split()))

# Output
print(maximum_increase(n, arr))
9 changes: 9 additions & 0 deletions A- Floor NUmber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
t= int(intput())
for _ in range(t):
n,x = map(int , input.spilt())
floor =1
apartment_count=2
while n> apartment_count:
apartment_count += x
floor += 1
print(floor)
Empty file added A-Floor Number(Java)
Empty file.
21 changes: 21 additions & 0 deletions A-Floor Number(Java).java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner
public class Main{
public static void main(String [] lol){
Scanner scanner = new Scanner(System.in);
int t= scanner.nextInt();
for(int i =0;i<t;i++){
int n= scanner.nextInt(); // room number where she lives
int x= scanner.nexxtInt(); // number of rooms per floors
int floor =1;
int apartmentCount =2;
while(n > apartmentCount){ // brute froces
apartmentCount += x;
floor ++;
}
System.out.println(floor);


}
scanner.close();
}
}