0~25만의 수 1개를 입력으로 받으면 그 수를 암호화하여 출력하는 프로그램을 작성하세요. 방법은 다음과 같습니다. 1. 입력받은 수의 제곱근에 1000을 곱한다. (예시: 2 => 1.414213... * 1000 => 1414.213...) 2. 1의 결과에서 소수점 이하를 버림한다. (예시: 1414.213... => 1414) 3. 2의 결과에서 입력받은 수를 뺀다.(예시: 1414 => 1414 - 2 => 1412) 이렇게 하면 2를 입력받았을 때 1412를 출력합니다. 다음 결과로 테스트하세요.
>>> password(2)
1412
>>> password(125000)
228553
>>> password(250000)
250000
>>> password(100000)
216227
난이도 Lv.1 예상합니다.
56개의 풀이가 있습니다.
python 3.8.7입니다.
import math
def password(n):
converted = int(math.sqrt(n) * 1000) - n
return converted
실행 결과입니다.
>>> password(2)
1412
>>> password(125000)
228553
import.java.util.*;
public class TEST {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int password = in.nextInt();
int encrypt = math.sqrt(password) * 2 - password;
System.out.println(encrypt);
}
}
import math
n = int(input())
def password(n):
x = int(math.sqrt(n) * 1000) - n
return x
print(password(n))
def password(number):
import math
number = math.sqrt(number) * 1000
number = int(number)
number = number - 2
print(number)
password(2)
password(3)
#include <stdio.h>
#include <math.h>
void main() {
float i, result;
printf("값을 입력해주세요 : ");
scanf_s("%f", &i);
result = (pow(i,0.5) * 1000) - i;
printf("%d", (int)result);
return 0;
}
C언어로 작성
x=int(input('0~25만의 정수 하나 입력'))
def password(e):
org=e
e=1000*e**0.5
e=int(e)
e-=2
return e
print(password(x))
using System;
namespace 문제풀이_콘솔
{
class Program
{
public static double password(double num)
{
double Sqrt = Math.Sqrt(num); //제곱근을 구함
double result = Math.Truncate(Sqrt*1000) - num;
return result;
}
static void Main(string[] args)
{
Console.Write("password : ");
string input = Console.ReadLine();
Console.WriteLine(password(Convert.ToDouble(input)));
}
}
}
def password(num):
return int(num**0.5 * 1000)-num
print(password(2))
print(password(125000))
print(password(250000))
print(password(100000))
Julia 입니다.
const password(n) = Int(floor((1000 * √n) - n))
let s = parse(Int, readline())
s |> password |> println
end
import java.util.Random; import java.util.Scanner;
//암호화 하기 public class PassCode { public static void main(String[] args) { double a=0;//임의의 수 0~~~25만 double b=0;//제곱근 int c=0;//정수로 바꾸기
Scanner scan= new Scanner(System.in);
Random ran= new Random();
a= ran.nextInt(250000);
System.out.println("=====>password("+a+")");
b=(int)Math.floor(Math.sqrt(a)*1000);
System.out.println(b);
}//main }//class
import math
def password(n):
code_num = math.floor(math.sqrt(n)*1000) - n
return code_num
n = int(input())
print(password(n))
math 패키지를 활용, def로 정의한 후 숫자를 input 받아 처리하는 로직
import math
def password(i):
a = math.trunc(int(i)**(1/2)*1000)-int(i)
print(a)
x = input("숫자를 입력하세요. : ")
password(x)
import math
password = int(input())
if password in range(250000+1):
print(math.floor(1000*math.sqrt(password))-password)
else: print("password is not in range")
import math
x = int(input('암호화 :'))
if 0<x<250000 :
i = int(math.sqrt(x)*1000)-x
print(i)
else : print('25만 이하로 입력하세요')
import math
n = int(input("숫자를 입력 바랍니다 : "))
value = int(math.sqrt(n) *1000) - n
print("해당 값 : " ,value)
#codingdojing_encryption
from math import *
def password(n):
print(floor(sqrt(n)*1000)-n)
password(2)
password(125000)
password(250000)
password(100000)
파이썬 3.8.10으로 작성했습니다.
import math
password = input().strip()
print(eval(str(math.sqrt(int(password))*1000).split('.')[0] + '-' + password))
C#
using System;
namespace 수암호화프로그램
{
class Program
{
static void Main()
{
Console.WriteLine(GetPassword(100000));
}
static int GetPassword(int number) => (int)(Math.Sqrt(number) * 1_000) - number;
}
}
def password(n):
x= int(n**0.5 * 1000) - n
return x
test=[2,125000,250000,100000]
for i in test:
print(password(i))
static void password(int x) {
System.out.println((int) (Math.sqrt(x) * 1000) - x);
}
public static void main(String[] args) {
password(2);
password(125000);
password(250000);
password(100000);
}
코딩 배운지 1주일도 안 된 코린이입니다. 꾸벅.
a = int(input("0 - 250000의 정수를 입력하세요."))
b = int((a**(1/2))*1000) - a
print(">>>>password(%d)" % a, "\n%d" % b)
security = int(input(">>password :"))
security = int((security**(1/2))*1000) - security
print(security)
import math
a = int(input())
def password (a) :
a1 = math.sqrt(a)*1000
a2 = math.trunc(a1)
a3 = a2 - a
return print(a3)
password(a)
import java.util.Scanner;
import java.util.*;
public class Password {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int password = sc.nextInt();
double encrypt = Math.sqrt(password) * 1000; //1.입력받은수 제곱근값에 1000을 곱한다
encrypt = Math.round(encrypt); //2.소수점을 버린다
encrypt -= password; //3.2의 결과에서 입력받은수를 뺀다
System.out.println(encrypt);
}
}
package org.javaturotials.ex;
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
num = (Math.sqrt(num)*1000)-num;
int a =(int)num;
System.out.println(a);
}
}
package section01;
import java.util.Scanner;
public class MathCalc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("숫자를 입력해주세요 : ");
int num = sc.nextInt();
int num2 = (int)(Math.sqrt(num) * 1000);
int result = num2 - num;
System.out.println(result);
}
}
import java.util.Scanner;
public class Password {
public static void main(String[] args) {
System.out.println("입력하세요.");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
double num = Double.parseDouble(str);
double sqrtnum = Math.sqrt(num);
System.out.println((int)(sqrtnum*1000)-(int)num);
}
}
Python. 적절한 변수명 정하는 게 은근히 신경 쓰이는군요.
import math
origin=int(input('임의의 수를 입력하시오. : '))
processing_number=math.sqrt(origin)*1000//1
encoded_number=processing_number-origin
print('암호화된 수는 {0:0.0f}입니다.'.format(encoded_number))
python
import math
number = float(input("숫자를 입력하시오: "))
num = math.sqrt(number) * 1000
ciper = int(math.trunc(num) - number)
print(f"암호: {ciper}")
java
import java.util.Scanner;
public class password
{
public static void main(String[] args)
{
int num = 0; //입력받는 정수값
double number = 0.0; //암호화 과정 중간값
int new_password = 0; //새로운 암호
Scanner scanner = new Scanner(System.in);
System.out.printf("0~250000의 숫자를 입력해주세요");
num = scanner.nextInt();
number = Math.sqrt(num) * 1000;
number = Math.floor(number);
new_password = (int)number - num;
System.out.printf("%d", new_password);
}
}
using System;
namespace solution
{
class Program
{
static void Main(string[] args)
{
Console.Write("암호화 할 0~25만 사이의 수 1개를 입력하세요: ");
int N = int.Parse(Console.ReadLine());
Console.WriteLine((int)(Math.Sqrt(N) * 1000) - N);
}
}
}
import math
a = input ("숫자를 입력하세요: ")
n = int(a)
def password(n):
return math.trunc((n**0.5)*1000) - n
print (password(n))