Algorithm
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1114
Fixed Password
Adapted by Neilor Tonin, URI Brazil
Write a program that keep reading a password until it is valid. For each wrong password read, write the message "Senha inválida". When the password is typed correctly print the message "Acesso Permitido" and finished the program. The correct password is the number 2002.
Input
The input file contains several tests cases. Each test case contains only an integer number.
Output
For each number read print a message corresponding to the description of the problem.
Input Sample | Output Sample |
2200 |
Senha Invalida |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
int password;
cin >> password;
if (password == 2002){
cout << "Acesso Permitido" << endl;
break;
}
else{
cout << "Senha Invalida" << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
while(true){
int password = input.nextInt();
if (password == 2002){
System.out.println("Acesso Permitido");
break;
}
else{
System.out.println("Senha Invalida");
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
while(true){
var password = parseInt(lines.shift());
if (password == 2002){
console.log("Acesso Permitido");
break;
}
else{
console.log("Senha Invalida");
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
while(True):
password = int(input())
if (password == 2002):
print("Acesso Permitido")
break
else:
print("Senha Invalida")
Copy The Code &
Try With Live Editor
Input
Output