Algorithm
Problem Name: beecrowd | 3299
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/3299
Small Unlucky Numbers
By Tomas Peiretti, UTN - FRSF Argentina
Timelimit: 1
An unlucky number is one that contains a 1 followed by a 3 among its digits. For example, the number 341329 is an unlucky number, while the number 26771 is not.
Given an integer N, your program will have to determine if N is unlucky or not.
Input
The input consists of a positive integer N (0 <= N <= 10¹⁷)
Output
Print the message "N es de Mala Suerte" if N is an unlucky number, otherwise print "N NO es de Mala Suerte".
Input Sample | Output Sample |
13 |
13 es de Mala Suerte |
12321 |
12321 NO es de Mala Suerte |
Code Examples
#1 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const [num] = readFileSync("/dev/stdin", "utf8").split("\n")
const esMalaSuerte = (str = "") => /13/.test(str)
console.log(`${num}${esMalaSuerte(num) ? "" : " NO"} es de Mala Suerte`)
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char a[100];
scanf("%s", &a);
char *ver = strstr(a, "13");
if (ver){
printf("%s es de Mala Suerte\n", a);
}else{
printf("%s NO es de Mala Suerte\n", a);
}
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C# Programming
Code -
C# Programming
using System;
//Developed by: @LucasMarcuzo
namespace _3299_Numeros_Má_Sorte_Pequenos
{
class Program
{
static void Main(string[] args)
{
string num = Convert.ToString(Console.ReadLine());
if (num.Contains("13")) {
Console.WriteLine("{0} es de Mala Suerte",num);
}
else {
Console.WriteLine("{0} NO es de Mala Suerte",num);
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Python Programming
Code -
Python Programming
lista = input()
lista1 = int(lista)*10
lista1 = str(lista1)
vetor = list(map(int,lista1))
tam = len(vetor)
esmalas = False
for i in range(tam):
if(vetor[i] == 1):
if(vetor[i+1] == 3):
esmalas = True
print("{} es de Mala Suerte".format(lista)) if esmalas else print("{} NO es de Mala Suerte".format(lista))
Copy The Code &
Try With Live Editor
Input
Output