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));
}
}
xxxxxxxxxx
#include<stdio.h>
int stack[10000000]={0};
int top=-1;
void push(int c)
{
stack[++top]=c;
}
void pop()
{
stack[top--]=0;
}
int main()
{
int N,max=0;
int order=1;
scanf("%d",&N);
int arr[N];
for(int i=0;i<N;i++)
{
scanf("%d",&arr[i]);
if(max<arr[i])
max=arr[i];
}
for(int i=0;i<N;i++)
{
while(top!=-1 && stack[top]==order)
{
order++;
pop();
}
if(arr[i]==order)
{
order++;
}
else
push(arr[i]);
}
while(top!=-1 && stack[top]==order)
{
order++;
pop();
}
if(order==max+1)
printf("Happy");
else
printf("Sad");
}
xxxxxxxxxx
public class testint
{
public static void main(String[] args)
{
boolean contain= false;
int valeurATrouver=5;
int ints[] ={1,4,5};
for(int i=0;i<ints.length;i++)
{
if(ints[i]==valeurATrouver)
{
contain=true;
}
}
if(contain){System.out.println("La valeur "+valeurATrouver+" est comprise dans le tableau");}
else{System.out.println("La valeur "+valeurATrouver+" n'est pas comprise dans le tableau");}
}
}
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
import check50
import check50_java
@check50.check()
def book_exists():
"""Book.java exists."""
check50.exists("Book.java")
@check50.check(book_exists)
def book_compiles():
"""Book.java compiles."""
check50_java.compile("Book.java")
@check50.check()
def press_exists():
"""Press.java exists."""
check50.exists("Press.java")
@check50.check(press_exists)
def press_compiles():
"""Press.java compiles."""
check50_java.compile("Press.java")
@check50.check()
def vm_exists():
"""VendingMachine.java exists."""
check50.exists("VendingMachine.java")
@check50.check(vm_exists)
def vm_compiles():
"""VendingMachine.java compiles."""
check50_java.compile("VendingMachine.java")
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
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);
}
}
}