-- 예전 기록/BOJ

[ BOJ ] 2743 : 단어 길이 재기 ( BRONZE 5 ) / C, C++, Python, Java

rejo 2023. 9. 23. 14:52

문제

알파벳으로만 이루어진 단어를 입력받아, 그 길이를 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 영어 소문자와 대문자로만 이루어진 단어가 주어진다. 단어의 길이는 최대 100이다.

출력

첫째 줄에 입력으로 주어진 단어의 길이를 출력한다.

풀이 과정

단어를 입력받고, length 를 구하는 함수를 사용하여 단어의 길이를 출력한다.

C

#include <stdio.h>
#include <string.h>

int main(void) {
    char word[101];
    scanf("%s", word);
    printf("%d", strlen(word));
    return 0;
}

C++

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    string word; cin >> word;
    cout << word.length();
    return 0;
}

Python

print(len(input().rstrip()))

Java

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String word = sc.nextLine();
        System.out.println(word.length());
    }
}