Skip to content

Instantly share code, notes, and snippets.

@marinhoarthur
Last active April 25, 2017 20:26
Show Gist options
  • Save marinhoarthur/13f84d89d23df10cd05c to your computer and use it in GitHub Desktop.
Save marinhoarthur/13f84d89d23df10cd05c to your computer and use it in GitHub Desktop.
Coding Marathon I - UnP (challenges 2, 4, 6)
import java.util.Scanner;
public class Dois
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i < n; i++)
{
int x = in.nextInt();
int[] a = getSequencia();
if(x > 0)
{
System.out.println(
somaRecursiva(a[x-1]) +
" " +
( somaRecursiva(a[x-1]) + (a[x-1] + 1) )
);
}
}
in.close();
}
// retorna sequencia de 2 em 2
// Ex: 1,3,7...
public static int[] getSequencia()
{
int vetor[] = new int[2000];
int aux = 1;
for(int i = 0; i < 2000; i++)
{
vetor[i] = aux;
aux+=2;
}
return vetor;
}
// tipo fatorial soh que a operacao matematica eh soma
public static int somaRecursiva(int i)
{
int r = 0;
int aux = i;
for(int j = 0; j < aux; j++)
{
r += i;
i--;
}
return r;
}
}
import java.util.Scanner;
public class Quatro
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int w = 0; w < n; w++)
{
Scanner in2 = new Scanner(System.in);
String str = in2.nextLine();
if(str.length() < 80)
{
str = str.replace("!", "");
str = str.replace("?", "");
str = str.replace(",", "");
str = str.replace(" ", "");
str = str.replaceAll("[1-9]", "");
String strTratada = str.replaceAll("[aeoiu]", "*");
int vogais = 0;
for(int i = 0; i < strTratada.length(); i++)
{
if(strTratada.charAt(i) == '*')
{
vogais++;
}
}
System.out.println(vogais);
System.out.println( (strTratada.length() - vogais) );
}
in2.close();
}
in.close();
}
}
import java.util.Scanner;
public class Seis
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i < n; i++)
{
int x = in.nextInt();
int y = in.nextInt();
if(
(x >= 0) && (x <= 100) &&
(y >= 0) && (y <= 100)
)
{
int result = 0;
if(x > 2 || y > 2)
{
result = (y - 1) * (x - 1);
}
System.out.println(result);
}
}
in.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment