양의 정수만 입력으로 받고 그 수의 자릿수를 출력해보자. ex1) 3 > 1자리수, ex2) 649 > 3자리수 ....
187개의 풀이가 있습니다.
#자릿수구하기
print("양의정수만 입력하세요")
n = int(input())
a = 0
while n >= 1:
n = n / 10
a = a + 1
print("자릿수는", a, "입니다.")
python을 잘 못쓰기에 연습하는겸 한번 적어봅니다. (다들 실력이 ㅎㄷㄷ...)
N = int(input('Enter number(N > 0) : '))
digit = 0
while True :
if N // 10**digit == 0: break
digit += 1
print(digit)
#include "stdafx.h"
#include <iostream>
int main()
{
int num;
std::cin >> num;
if (num / 10000) std::cout << num << "은 5자리수 입니다.";
else if (num / 1000) std::cout << num << "은 4자리수 입니다.";
else if (num / 100) std::cout << num << "은 3자리수 입니다.";
else if (num / 10) std::cout << num << "은 2자리수 입니다.";
else std::cout << num << "은 1자리수 입니다.";
return 0;
}
이렇게푸는게 아닌것같지만 나름대로 짠걸 올려봅니다..
public class Cipher {
public static void main(String[] args) {
int count=0;
int number=10000;
while(number>0) {
number/=10;
count++;
}
System.out.println(count);
}
}
Ruby
digit = -> { puts "#{gets.to_i.digits.size}자리수" }
Test
# cases : 3, 649, 0649
$stdin = StringIO.new("3\n")
expect { digit.call }.to output("1자리수\n").to_stdout
$stdin = StringIO.new("649\n")
expect { digit.call }.to output("3자리수\n").to_stdout
$stdin = StringIO.new("0649\n")
expect { digit.call }.to output("3자리수\n").to_stdout
int main(void) { double num1 = 0; int cnt = 1,int j=10;
scanf_s("%lf", &num1);
for (int i = 1; i < 50; i++)
{
num1 = num1 / j;
if(num1<1 || num1==1)
{
printf("%d", cnt);
break;
}
cnt++;
}
system("pause");
return 0;
}```{.cpp}
int main(void) { double num1 = 0; int cnt = 1,int j=10;
scanf_s("%lf", &num1);
for (int i = 1; i < 50; i++)
{
num1 = num1 / j;
if(num1<1 || num1==1)
{
printf("%d", cnt);
break;
}
cnt++;
}
system("pause");
return 0;
} ```
#include<iostream>
using namespace std;
int solution(int n)
{
int remain = 0, reauq = n, count = 0;
while (reauq != 0)
{
remain = reauq % 10;
reauq /= 10;
count++;
}
return count;
}
int main()
{
int num = 24;
cout << solution(num) <<"자릿수 숫자입니다"<< endl;
}
import java.util.Scanner;
public class Evangelion {
public static void main(String[] args) {
int a,b;
System.out.println("입력하신 숫자의 자릿수를 알려드립니다.");
Scanner sc = new Scanner (System.in);
int result;
a = sc.nextInt();
b = 0;
while(a>0) {
a/=10;
b++;
}
System.out.println(b);
}
}
while True: a=int(input('a:')) n=0
while a<0:
a=int(input('a:'))
while a>10**n:
n+=1
print(str(n)+'자릿수...')
public class test {
public static void main(String[] args) {
int a=0;
int b=10000;
while(b>0) {
b/=10;
a++;
}
System.out.println(a);
}
}
a = int(input("양의 정수를 입력해주세요: "))
if a > 0 : print("{} > {}자리수".format(a, len(str(a))))
else : print("양의 정수가 아닙니다.")
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("수를 입력 : ");
int num = sc.nextInt();
String result = ""+num;
System.out.println(result.length()+"자리수");
}
while True:
try:
x = int(input('정수를 입력하세요. '))
if x >= 0:
print('입력하신 숫자는', x, '이고 자릿수는', len(str(x)), '입니다.')
break
else: print('양의 정수를 입력하세요.')
except ValueError:
print('정수가 아닙니다.')
n = input()
if int(n) != float(n) or int(n) <= 0: raise RuntimeError('자연수를 입력하세요')
print('%d 자리' % len(str(n)))
using System;
namespace CD164
{
class Program
{
static void Main(string[] args)
{
Console.Write("양의 정수 입력: ");
var input = int.Parse(Console.ReadLine());
Console.WriteLine($"{input} > {(int)Math.Log10(input) + 1}자리수");
}
}
}
int main() { int number,num; int i,count = 0;
printf("숫자를 입력해주세요 : ");
scanf("%d", &number);
for (num = number;num>0 ;count++) {
num /= 10;
}
printf("%d > %d자리수", number, count);
}
public void GetPrintDigitOfNumber(int input)
{
int count = 1;
string numberString = input.ToString();
for (int i = 1; i < numberString.Length; i++)
{
count++;
}
Console.WriteLine($"{input}는 {count}의 자릿수");
}
public class Javatutorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(("" + n).length());
}
}
import java.util.InputMismatchException;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.println("숫자를 입력해 주세요 : ");
Integer temp = sc.nextInt();
System.out.println(temp.toString().length() + "자릿수");
} catch (InputMismatchException e) {
System.out.println("ERR");
e.printStackTrace();
}
}
}
c언어
#include<stdio.h>
int main()
{
int num;
int count =0;
scanf("%d", &num);
int temp_num = num;
while(num>0)
{
count++;
num = num/10;
}
printf("%d는 %d 자리수입니다. \n ", temp_num ,count);
return 0;
}
list = input("자릿수를 출력하는 프로그램 ex1) 3>1자리수, ex2)649 > 3자리수 : ")
list = str(list)
print("%s" %list+">"+"%d" %len(list)+"자리수")
Kotlin
fun main(args : Array<String>){
val n: Int = args[0].toInt()
println("${n.toString().length}자리수")
}
package test;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println((sc.nextInt() + "").length());
}
}
int n = 1000;
int sum = 0;
for (int i = 1; i < n; i++) {
if (i % 3 == 0 || i % 5 == 0) {
sum += i;
}
}
System.out.println(sum);
}
import java.util.Scanner;
public class TEST12 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
printResult(n);
}
public static void printResult(int n) {
int len = String.valueOf(n).toCharArray().length;
StringBuilder sb = new StringBuilder();
sb.append(len).append(" 의자리수");
System.out.println(n + " is " + sb.toString());
}
}
def calc_digit(input):
assert input > 0
return (len(str(input)))
test_input = [3, 649]
test_output = [1, 3]
assert calc_digit(test_input[0]) == test_output[0]
assert calc_digit(test_input[1]) == test_output[1]
input1 = -1
while input1 <= 0:
input1 = int(input("Input plus integer : "))
print(str(calc_digit(input1)) + '자리수')
public static void main(String[] args) {
Random input = new Random();
int []arr = {9,7,6,4,5,4,0,1,3,2};
System.out.print("초기값 : ");
for (int i = 0; i<10; i++) {
System.out.print(arr[i] + (i < 9 ? " " : "\n변경후 : "));
}
for (int i = 0; i<10; i++) {
arr[i] = input.nextInt(9);
System.out.print(arr[i] + (i < 9 ? " " : "\n"));
}
}
import java.util.Scanner;
class CodingDojang {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("정수를 입력하세요 : ");
int num = input.nextInt();
int count=0;
for (int i=1;i>0;i*=10) {
if((num/i)>0){
count++;
}else{
break;
}
}
System.out.println(count+"자리수");
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String num = scan.nextLine();
System.out.println(num.length()+"자리수");
}
}
import java.util.Scanner;
public class KimSanghyeop
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("입력 : ");
int num = sc.nextInt();
int cnt=-1;
do
{
num = num / 10;
cnt++;
}while(num!=0);
System.out.println((int)Math.pow(10, cnt)+ "자리수");
}
}
def cha(): while True: num = input() if int(num) < 0: print('양의 정수만 입력하세요') continue else: break print('%d자리수입니다' % len(str(num)))
#include <stdio.h>
int main(void)
{
int cnt = 0;
int num;
printf("양의 정수 입력:");
scanf_s("%d", &num);
while (num!=0)
{
num = num / 10;
cnt++;
}
printf("%d자리수였습니다.", cnt);
return 0;
}
#include <stdio.h>
int main(void){
int num,size;
printf("숫자 입력 : ");
scanf("%d",&num);
size = 0;
while(num > 0){
num /= 10;
size++;
}
printf("\n %d 자릿수",size);
return 0;
}
namespace codingdojang__
{
class Program
{
static void Main(string[] args)
{
int total = 0;
int input = int.Parse(Console.ReadLine());
for (int temp = 1; temp <= input.ToString().Length; temp++)
{
total += 1;
}
Console.WriteLine("{0}자리수",total);
}
}
}
#include <stdio.h>
void main()
{
int num, count = 0;
printf("수 입력 : ");
scanf("%d", &num);
for (; num > 0; count++)
{
num /= 10;
}
printf("%d자리수\n", count);
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int func(int num) {
int base = 1;
int count = 0;
while (base <= num) {
base *= 10;
count++;
}
return count;
}
int main() {
int num;
scanf("%d", &num);
int count = func(num);
printf("%d자리\n", count);
return 0;
}
import java.util.Scanner;
public class Problem164 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("양의 정수");
long a = scan.nextLong();
scan.close();
System.out.println(a+"는 "+String.valueOf(a).length()+"자리수");
}
}
static void Main(string[] args)
{
Console.WriteLine("*** 코딩도장 Q164 ***");
string uip;
int tmp = 0;
Console.WriteLine("");
Console.Write("양의 정수를 입력하세요 : ");
uip = Console.ReadLine();
tmp = int.Parse(uip);
if (tmp>=0)
{
Console.WriteLine("입력하신 {0} 는 {1} 자리의 수입니다.", uip, uip.Length);
}
else
{
Console.WriteLine("입력하신 수는 0보다 작습니다.");
}
}
비쥬얼 스튜디오 작성했습니다. while문으로 처리했습니다.
#include <stdio.h>
void main() {
int y;
printf("정수를 입력하세요 : ");
scanf("%d", &y);
int x = y;
int cnt = 0;
while ( x / 10 > 0) {
cnt++;
x = x / 10;
if (x / 10 == 0)
cnt++;
}
printf("%d는 %d자리 숫자입니다.", y, cnt);
}
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String numStr = in.next();
int answer = numStr.length();
System.out.println(numStr+">"+answer+"자리수");
}
}
n=int(input())
ans=1
while int(n/10)!=0:
ans+=1;n/=10
print(ans,'자리 수')
각 자릿수의 숫자들을 반환하는줄 알았는데, 단순히 몇 자리의 수 인지 판단하는 문제였군요.
n=int(input("Enter the positive int")) x=0 while True: n=n/10 x=x+1 if n<1: break
print("해당 숫자는",x,"자리수입니다.")
python입니다.
def digit(num):
num = str(num)
return len(num)
print(str(digit(3)) + "자리수")
print(str(digit(649)) + "자리수")
package d164_cipher;
import java.util.Scanner;
public class Cipher {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int in=sc.nextInt();
int i, output=0;
for(i=1; in/i>0; output++) i*=10;
System.out.println("Output: "+output);
sc.close();
}
}
파이썬 3.*
# Ciphers
n = int(input("Input a positive integer : "))
cnt = 0
while n > 0:
n = n // 10
cnt += 1
print("Ciphers :", cnt)
import java.util.*;
public class 자릿수를출력하는프로그램 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] num = scan.nextLine().split("");
System.out.println(num.length+"자릿수");
}
}
파이썬 입니다
def num_length(a):
return (f'{len(a)} 자릿수 입니다.')
print(num_length((input("양의 정수를 입력하세요 :"))))
def abc():
a = int(input("양의 정수를 입력하세요 : "))
if a < 1:
print("양의 정수를 입력해주세요")
else :
print(len(str(a)))
b = abc()
jungsu = str(input("정수를 입력하세요>"))
list= (jungsu)
for lists in range(len(list)+1):
if len(list) == lists:
print("%d 자리수" %lists)
break
int CipherCounter(int a)
{
int Counter = 1;
while(a>=10)
{
a = a /10 ;
Counter++;
}
return Counter;
}
while True:
n=input("양의 정수 n을 입력하십시오: ")
if int(n)<=0:
print("잘못된 입력입니다")
else:
print("n은 "+str(len(n))+"자리수입니다.")
n = int(input("양의 정수:"))
for i in range(1,101,1) :
digit = n // 10**i
if digit == 0:
print("%d자릿수"%i)
break
a=int(input())
if a>0:
print(str(len(str(a)))+'jarisu')
else:
print("please input number bigger than 0")
while True:
try:
a = int(input("양의 정수만 입력"))
if a > 0:
b = len(str(a))
print("{}자리수인 숫자입니다.".format(b))
break
except:
print("양의 정수만 입력해주세요!!\n")
print(f"{len(str(int(input())))}자리")
파이썬 3.6버전 이상부터 사용 가능한 f-string을 사용해 풀었습니다. 앞에 0이 있더라도 자릿수를 정확히 출력합니다
파이썬으로 작성했습니다.
def check_num():
num = input("양의 정수를 입력해 주세요. : ")
try:
num = int(num)
if num > 0:
print(f"입력받은 숫자는 {len(str(num))}자리수 입니다.")
else:
check_num()
except:
check_num()
check_num()
import java.util.Scanner;
public class Q163 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("양의 정수를 입력해주세요");
int a = scan.nextInt();
String[] b = Integer.toString(a).split("");
if (a > 0) {
System.out.println(b.length+"자리수");
} else System.out.println("양의 정수만 입력해주세요");
scan.close();
}
}
#number_of_digit.py
input_number = input("Input a positive integer : ")
number_of_digits = 0
while input_number:
input_number = input_number / 10
number_of_digits +=1
print "numnber_of_digits : %d\n"%number_of_digits
#include<stdio.h>
int main(void) {
int inside;
int jare = 1;
int outside = 0;
printf("양의 정수를 입력하세요 : ");
scanf_s("%d", &inside);
while (true) {
if (inside / jare >= 1) {
outside++;
jare *= 10;
}
else
break;
}
printf("%d자리수 입니다 ", outside);
return 0;
}
package test;
import java.util.*;
public class Test{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
int i=1;
int count = 1;
while(true) {
if(input / i == 0) {
System.out.print(count-1+"자리 수");
break;
}
i *= 10;
count++;
}
sc.close();
}
}
namespace _60일차_9월30일
{
class MainApp
{
static void Main(string[] args)
{
//양의 정수만 입력으로 받고 그 수의 자릿수를 출력해보자. ex1) 3 > 1자리수, ex2) 649 > 3자리수
Console.Write("Input Number : ");
string Input = Console.ReadLine();
char[] Data = Input.ToCharArray();
Console.WriteLine($"{Data.Length}자리수");
}
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("숫자 입력 : ");
int number = scan.nextInt();
System.out.printf("%d자리", (int)(Math.log10(number)+1));
}
class DoNumber:
def __init__(self):
self.digit = 0
def printDigits(self,n):
i = 0
while True:
if n>=10**i and n<10**(i+1):
self.digit = i+1
break
i+=1
print(self.digit)
a = DoNumber()
a.printDigits(3)
a.printDigits(10)
a.printDigits(649)
a.printDigits(7676)
def num(a):
temp = int(a)
count = 0
while (temp // 10) >= 1:
count += 1
temp = temp // 10
count += 1
print(count)
num(input('INPUT:'))
import java.util.Scanner;
public class test {
//양의 정수만 입력으로 받고 그 수의 자릿수를 출력해보자
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("입력할 양의 정수는 : ");
double input = sc.nextDouble();
while (input <= 0) {
System.out.println("양의 정수로 입력하시오. : ");
input = sc.nextInt();
}
int n = 0;
int c = 1;
double a = Math.pow(10, n);
while(true) {
if(input/a >= 10) {
n++;
c++;
a = Math.pow(10, n);
}
if(input/a < 10) {
break;
}
}
System.out.println("입력한 양의 정수는 " + (int) input + "이며, " + c + "자리의 수 입니다.");
sc.close();
}
}
num = int(input())
count = 0
while 1:
if(num):
if(num % 10 == 0):
while(num):
num = num // 10
count += 1
else:
num = num // 10
count+= 1
else:
break
print("%d자리" %count)
심심해서 len함수 안쓰고 풀어봤어요
def digits(a):
... if a > 0 and str(round(a)) == str(a):
... return str(len(str(a))) + "자릿수"
... else:
... return "잘못된 입력값"
...
>>> digits(5)
'1자릿수'
>>> digits(15)
'2자릿수'
def digit_of_number():
input_number=input("숫자 자릿수 판별하기: 숫자를 입력해주세요.")
print(len(input_number))
digit_of_number()
# 다음에 풀때 반복문과 int 형태로만 계산해서 풀기
def place_digit():
x = 0
while x <= 0:
x = int(input("Please input positive number: "))
print("Place number of {0} is {1}".format(x,len(str(x))))
파이썬 3.8.10으로 작성되었습니다. map 함수를 통해 int형 만을 받을 수 있습니다. 정수가 아닌 경우 ValueError이 발생합니다.
a = list(map(int, input().split()))[0]
print(a, ' > ', len(str(a1)), ' 자리수')
while True:
n = input("Positive value: ")
try:
if int(n) > 0: print(len(n))
else: raise
break
except:
pass
static void number(int x) {
if((x + "").length() > 0) {
System.out.print("입력 : " + x + " 출력 : 1");
}
for (int i = 0; i < (x + "").length()-1; i++) {
System.out.print("0");
}
System.out.println("자리 수 입니다.");
}
public static void main(String[] args) {
number(156);
number(2458);
number(15);
number(9);
}
while True :
a= int(input("양의 정수만 입력해주세요"))
if a>= 0 :
break
b = list("".join(str(a)))
print(len(b))
num = int(input("양의 숫자만 입력: "))
if num > 0:
A = list(map(int, str(num)))
print(str(len(A)) + "자리수")
else:
print("ERROR")
n = input('양의 정수를 입력하세요: ')
if n[0] == '-' and n[1].isdecimal():
print('잘못된 입력입니다.')
else:
try:
int(n)
print(f'{len(n)}자리수')
except ValueError:
print('잘못된 입력입니다.')
자연수 / 10.pow(n) < 1을 만족하는 최소 n이 자연수의 자리수. 그러나, 숫자 형태가 맞다면, 문자열의 길이를 구하는게 더 쉽습니다.
// Rust
use std::str::FromStr;
fn main() -> Result<(), std::num::ParseIntError> {
let number = "649";
// if you prefer key input...
// let mut number = String::new();
// std::io::stdin().read_line(&mut number).expect("input error");
// let number = number.trim();
let _ = usize::from_str(&number)?;
println!("{}", number.len());
Ok(())
}
using System;
using System.Collections.Generic;
namespace FirstProgram
{
class Program
{
static void Main(string[] args)
{
Console.Write("양의 정수를 입력하세요 : ");
string x = Console.ReadLine();
Console.WriteLine(x.Length + "자리수 입니다");
}
}
}
C#
package com.algorithm.algorithmpractice.dojang;
import java.util.Scanner;
public class Digit {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("숫자입력하기");
int inputNum = input.nextInt();
int digit = 0;
while (true){
inputNum /= 10;
digit++;
if(inputNum == 0){
break;
}
}
System.out.println(digit);
}
}
ui = input("자릿수를 출력합니다. 양의 정수 입력>> ")
if ui[0]=='-' or ui[0]=='0':
print("오류")
else:
a=[ i for i in ui ]
print("%d >> %d자리수" % (int(ui), len(a)))
파이썬 3.8.5
private static int positionNum() {
Scanner sc = new Scanner(System.in);
System.out.println("양의정수를 입력하세요~~");
int pNum = sc.nextInt();
if(pNum <= 0) {
System.out.println("양의 정수만 입력가능합니다.");
return 9999;
}
String strpNum = String.valueOf(pNum);
String[] pNumArray = strpNum.split("");
return pNumArray.length;
}
while True: try: n=int(input('양수를 입력하세요: ')) if n>=0: break except ValueError: pass
result=list(str(n)) print('{0}은 {1}자리 숫자입니다'.format(n,len(result)))
num = int(input('양의 정수를 입력하세요.'))
def pos_len():
if num>0:
n=len(str(num))
print('입력한 숫자는',n,'자리수입니다.')
elif num<=0:
print('양의 정수가 아닙니다. 프로그램을 종료합니다.')
pos_len()