Ici je répertorie quelques fonctions que je réutilise pour des exercices ou challenges (quand j'y pense)
import "strconv"
func StringToNumber(str string) int {
n, _ := strconv.Atoi(str)
return n
}
#include <string>
using namespace std ;
string reverseString (string str ){
string result = "";
for(int i = str.size()-1; i >= 0; i--){
result += str[i];
}
return result;
}
local contains = {}
function contains.check(a, x)
for index, value in ipairs(a) do
if value == x then
return true
end
end
return false
end
return contains
endswith = {}
function endswith.strEndsWith(s, ending)
valid = true
print(s, ending)
if #s >= #ending then
dif = #s-#ending
for i=1, #ending do
print(s:sub(i+dif,i+dif),ending:sub(i,i))
if s:sub(i+dif,i+dif) ~= ending:sub(i,i) then
valid = false
end
end
return valid
else
return false
end
end
return endswith
r = true
col = {}
cell = {}
for j=1,9 do
col[j] = ""
cell[j] = ""
end
for i=1,9 do
next_token = io.read()
index = 1
for j=1,17,2 do
col[index] = col[index] .. string.sub(next_token,j,j)
if(i < 4 and index < 4) then
cell[1] = cell[1] .. string.sub(next_token,j,j)
elseif(i < 4 and index > 3 and index < 7) then
cell[2] = cell[2] .. string.sub(next_token,j,j)
elseif(i < 4 and index > 6) then
cell[3] = cell[3] .. string.sub(next_token,j,j)
elseif(i > 3 and i < 7 and index < 4) then
cell[4] = cell[4] .. string.sub(next_token,j,j)
elseif(i > 3 and i < 7 and 3 and index < 7) then
cell[5] = cell[5] .. string.sub(next_token,j,j)
elseif(i > 3 and i < 7 and index > 6) then
cell[6] = cell[6] .. string.sub(next_token,j,j)
elseif(i > 6 and index < 4) then
cell[7] = cell[7] .. string.sub(next_token,j,j)
elseif(i > 6 and 3 and index < 7) then
cell[8] = cell[8] .. string.sub(next_token,j,j)
elseif(i > 6 and index > 6) then
cell[9] = cell[9] .. string.sub(next_token,j,j)
end
index = index + 1
end
if(string.match(next_token,"[1+]") == nil
or string.match(next_token,"[2+]") == nil
or string.match(next_token,"[3+]") == nil
or string.match(next_token,"[4+]") == nil
or string.match(next_token,"[5+]") == nil
or string.match(next_token,"[6+]") == nil
or string.match(next_token,"[7+]") == nil
or string.match(next_token,"[8+]") == nil
or string.match(next_token,"[9+]") == nil
) then
r = false
end
end
for i=1,9 do
if(string.match(col[i],"[1+]") == nil
or string.match(col[i],"[2+]") == nil
or string.match(col[i],"[3+]") == nil
or string.match(col[i],"[4+]") == nil
or string.match(col[i],"[5+]") == nil
or string.match(col[i],"[6+]") == nil
or string.match(col[i],"[7+]") == nil
or string.match(col[i],"[8+]") == nil
or string.match(col[i],"[9+]") == nil
or string.match(cell[i],"[1+]") == nil
or string.match(cell[i],"[2+]") == nil
or string.match(cell[i],"[3+]") == nil
or string.match(cell[i],"[4+]") == nil
or string.match(cell[i],"[5+]") == nil
or string.match(cell[i],"[6+]") == nil
or string.match(cell[i],"[7+]") == nil
or string.match(cell[i],"[8+]") == nil
or string.match(cell[i],"[9+]") == nil
) then
r = false
end
end
print(r)
import java.util.*;
public class TableSubstract{
public static int[] arrayDiff(int[] a, int[] b) {
List<Integer> c = new LinkedList<Integer>(Arrays.stream(a).boxed().toList());
if(b.length > 0){
for(int i = 0; i < b.length; i++){
if(c.contains((Integer)b[i])){
while(c.contains((Integer)b[i])){
c.remove((Integer)b[i]);
}
}
}
}
return c.stream().mapToInt(Integer::intValue).toArray();
}
}
import java.util.*;
class Ascii{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int L = in.nextInt();
int H = in.nextInt();
in.nextLine();
String T = in.nextLine();
for (int i = 0; i < H; i++) {
String ROW = in.nextLine();
for(int j = 0; j<T.length(); j++)
{
if(T.charAt(j) == 'A' || T.charAt(j) == 'a')
{
for(int l = L-L; l < L; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'B' || T.charAt(j) == 'b')
{
for(int l = L; l < L*2; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'C' || T.charAt(j) == 'c')
{
for(int l = L*2; l < L*3; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'D' || T.charAt(j) == 'd')
{
for(int l = L*3; l < L*4; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'E' || T.charAt(j) == 'e')
{
for(int l = L*4; l < L*5; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'F' || T.charAt(j) == 'f')
{
for(int l = L*5; l < L*6; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'G' || T.charAt(j) == 'g')
{
for(int l = L*6; l < L*7; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'H' || T.charAt(j) == 'h')
{
for(int l = L*7; l < L*8; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'I' || T.charAt(j) == 'i')
{
for(int l = L*8; l < L*9; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'J' || T.charAt(j) == 'j')
{
for(int l = L*9; l < L*10; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'K' || T.charAt(j) == 'k')
{
for(int l = L*10; l < L*11; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'L' || T.charAt(j) == 'l')
{
for(int l = L*11; l < L*12; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'M' || T.charAt(j) == 'm')
{
for(int l = L*12; l < L*13; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'N' || T.charAt(j) == 'n')
{
for(int l = L*13; l < L*14; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'O' || T.charAt(j) == 'o')
{
for(int l = L*14; l < L*15; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'P' || T.charAt(j) == 'p')
{
for(int l = L*15; l < L*16; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'Q' || T.charAt(j) == 'q')
{
for(int l = L*16; l < L*17; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'R' || T.charAt(j) == 'r')
{
for(int l = L*17; l < L*18; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'S' || T.charAt(j) == 's')
{
for(int l = L*18; l < L*19; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'T' || T.charAt(j) == 't')
{
for(int l = L*19; l < L*20; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'U' || T.charAt(j) == 'u')
{
for(int l = L*20; l < L*21; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'V' || T.charAt(j) == 'v')
{
for(int l = L*21; l < L*22; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'W' || T.charAt(j) == 'w')
{
for(int l = L*22; l < L*23; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'X' || T.charAt(j) == 'x')
{
for(int l = L*23; l < L*24; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'Y' || T.charAt(j) == 'y')
{
for(int l = L*24; l < L*25; l++)
{
System.out.print(ROW.charAt(l));
}
}
else if(T.charAt(j) == 'Z' || T.charAt(j) == 'z')
{
for(int l = L*25; l < L*26; l++)
{
System.out.print(ROW.charAt(l));
}
}
else
{
for(int l = L*26; l < L*27; l++)
{
System.out.print(ROW.charAt(l));
}
}
}
System.out.println();
}
}
}
<?php
$r = 10000002;
fscanf(STDIN, "%d",
$N
);
for ($i = 0; $i < $N; $i++)
{
fscanf(STDIN, "%d",
$Pi[$i]
);
}
sort($Pi,SORT_NUMERIC);
for($i=0;$i<$N-1;$i++)
{
if($Pi[$i+1]-$Pi[$i] < $r)
{
$r = $Pi[$i+1]-$Pi[$i];
}
}
echo($r."\n");
?>