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
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
#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
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
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
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
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