xxxxxxxxxx
import java.util.*;
class Checker implements Comparator<Player>{
public int compare(Player a, Player b) {
// If 2 Players have the same score
if(a.score == b.score){
// Order alphabetically by name
if(a.name.compareTo(b.name) < 0){
return -1;
}
else if(a.name.compareTo(b.name) > 0){
return 1;
}
return 0;
}
// Otherwise, order higher score first
else if(a.score > b.score){
return -1;
}
else if(a.score < b.score){
return 1;
}
return 0;
}
}
/** Alternative Approach:
class Checker implements Comparator<Player>{
public int compare(Player a, Player b) {
// If 2 Players have the same score
if(a.score == b.score){
// Order alphabetically by name
return a.name.compareTo(b.name);
}
// Otherwise, order higher score first
return ((Integer) b.score).compareTo(a.score);
}
}
**/
class Player{
String name;
int score;
Player(String name, int score){
this.name = name;
this.score = score;
}
}
class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Player[] player = new Player[n];
Checker checker = new Checker();
for(int i = 0; i < n; i++){
player[i] = new Player(scan.next(), scan.nextInt());
}
scan.close();
Arrays.sort(player, checker);
for(int i = 0; i < player.length; i++){
System.out.printf("%s %s\n", player[i].name, player[i].score);
}
}
}
xxxxxxxxxx
array=list(map(int,input().split(",")))
array=sorted(array)
j=[]
j.append(array[0])
j.append(array[1])
for i in range(2,len(array)):
if j[i-1]+j[i-2] in array:
j.append(j[i-1]+j[i-2])
else:
break
print(j)
xxxxxxxxxx
import sys
import math
width = int(input())
height = int(input())
players = int(input())
class Player:
def __init__(self, x, y):
self.x = x
self.y = y
DIR = {'UP' : 'C', 'RIGHT' : 'A', 'DOWN' : 'D', 'LEFT' : 'E', 'STAY' : 'B'}
grid = [['?' for x in range(width)] for y in range(height)]
enemies = [Player(-1,-1) for e in range(players-1)]
player = Player(-1,-1)
def enemyAtPos(x, y):
for e in enemies:
if x == e.x and y == e.y:
return True
return False
def getPossibleMoves(x, y):
possibleMoves = []
if grid[(y-1)%height][x] != '#':
if not enemyAtPos(x, y-1) and not enemyAtPos(x, y-2) and not enemyAtPos(x-1, y-1) and not enemyAtPos(x+1, y-1):
possibleMoves.append([x, (y-1)%height])
if grid[y][(x+1)%width] != '#':
if not enemyAtPos(x+1, y) and not enemyAtPos(x+2, y) and not enemyAtPos(x+1, y-1) and not enemyAtPos(x+1, y+1):
possibleMoves.append([(x+1)%width, y])
if grid[(y+1)%height][x] != '#':
if not enemyAtPos(x, y+1) and not enemyAtPos(x, y+2) and not enemyAtPos(x-1, y+1) and not enemyAtPos(x+1, y+1):
possibleMoves.append([x, (y+1)%height])
if grid[y][(x-1)%width] != '#':
if not enemyAtPos(x-1, y) and not enemyAtPos(x-2, y) and not enemyAtPos(x-1, y-1) and not enemyAtPos(x-1, y+1):
possibleMoves.append([(x-1)%width, y])
return possibleMoves
xxxxxxxxxx
s=input()
l=[]
s1='aeiou'
sum1=0
def snm(sum1):
t=0
while(sum1>0 or t>9):
if(sum1==0):
sum1=t
t=0
t=t+sum1%10
sum1=sum1//10
return t
for i in range(len(s)):
if s[i] in s1:
l.append(i)
for j in range(len(l)):
k=l[j]*5
sum1=0
for h in range(1,k+1,2):
sum1=sum1+h
print(snm(sum1))
xxxxxxxxxx
def BitmapHoles(strArr):
bitmap = {}
for i in range(len(strArr)):
for j in range(len(strArr[i])):
bitmap[(i,j)] = int(strArr[i][j])
hole_count = 0
hole = set()
checked = set()
flag = True
for i in range(len(strArr)):
for j in range(len(strArr[i])):
stack = [(i,j)]
while stack:
coords = stack.pop()
if coords not in checked:
checked.add(coords)
if bitmap[coords] == 0 and coords not in hole:
hole.add(coords)
if flag == True:
hole_count += 1
flag = False
if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
stack.append((coords[0]-1,coords[1]))
if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
stack.append((coords[0]+1,coords[1]))
if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
stack.append((coords[0],coords[1]-1))
if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
stack.append((coords[0],coords[1]+1))
flag = True
return hole_count
xxxxxxxxxx
def BitmapHoles(strArr):
bitmap = {}
for i in range(len(strArr)):
for j in range(len(strArr[i])):
bitmap[(i,j)] = int(strArr[i][j])
hole_count = 0
hole = set()
checked = set()
flag = True
for i in range(len(strArr)):
for j in range(len(strArr[i])):
stack = [(i,j)]
while stack:
coords = stack.pop()
if coords not in checked:
checked.add(coords)
if bitmap[coords] == 0 and coords not in hole:
hole.add(coords)
if flag == True:
hole_count += 1
flag = False
if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
stack.append((coords[0]-1,coords[1]))
if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
stack.append((coords[0]+1,coords[1]))
if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
stack.append((coords[0],coords[1]-1))
if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
stack.append((coords[0],coords[1]+1))
flag = True
return hole_count
xxxxxxxxxx
def getUmbrellas(requirement, sizes):
for i in sizes:
if i > requirement:
pass
else:
q = requirement / i
r = requirement % i
if r == 0:
return q
if r in sizes:
return q + 1
return -1
xxxxxxxxxx
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Ingresa un numero para calcular su factorial: ");
int num = sc.nextInt();
System.out.println("Factorial de " + num + " es: " + factorial(num));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
xxxxxxxxxx
public static double area(int n, double side){
double area = ( n*side*side)/4* Math.tan(3.14/n);
return area;
}
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
System.out.println("Enter n and side");
int n = scan.nextInt();
double side = scan.nextDouble();
System.out.println(area(n, side));
}
}