본문 바로가기

CodeUp

C언어) CodeUp 1270 [1의 개수는? 1]

1270 : 1의 개수는? 1 해결

시간 제한: 1 Sec  메모리 제한: 128 MB

제출: 11793  해결 문제 수: 8160

 

문제 분류 : 보기

문제 설명  

구글 입사 시험으로 1 ~ 1,000,000까지 1의 개수를 묻는 문제가 나온적이 있다.

우리는 이 문제를 풀기에는 아직 힘이 든다.

우리는 이 문제를 조금 쉽게 바꾸어 풀려고한다.

어떤 수 n이 주어지면 1부터 n까지의 수 중 맨 마지막 자리에 1이 몇 번 들어 있는지 알아내는 프로그램을 작성하시오.

입력

n이 입력된다. ( 1 <= n <= 1,000,000 )

출력

맨 마지막 자리에 1이 몇 번 들어 있는지 출력한다.

입력 예시   예시 복사

35

출력 예시

4

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
 
int main()
{
    int i, n, cnt = 0
 
    scanf("%d"&n);
 
    for(i = 1; i <= n; i++)
    {
        if ( i % 10 == 1 )
            cnt++;
    }
 
    printf("%d", cnt);
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

/*스크롤 인디케이터 시작*/ .header { position: absolute; top: 0; z-index: 1; width: 100%; background-color: #fff; } .progress-container { width: 100%; height: 4px; background: #f6f6f6; } .progress-bar { height: 4px; background: #6C6C6C; width: 0%; } /*스크롤 인디케이터 종료*/ /*왼쪽, 좌측 밑의 이미지 추가 시작*/ /*가로의 길이가 1510일때까지는 보여라*/ @media screen and (min-width:1500px) { .main_ad { display:visible; position: absolute; left: 0px; bottom: 80px; cursor: pointer; z-index: 11; } } /*가로의 길이가 1511일까지는 보이지 말아라*/ @media screen and (max-width:1510px) { .main_ad { display:none; position: absolute; left: 0px; bottom: 80px; cursor: pointer; z-index: 11; } } /*왼쪽, 좌측 밑의 이미지 추가 종료*/ /*이웃추가버튼 추가 시작*/ @media screen and (min-width:500px) { .add_adBanner { display:visible; } } @media screen and (max-width:510px) { .add_adBanner { display:none; } } .add_adBanner ul { position: absolute; left: 10px; bottom: 22px; cursor: pointer; z-index: 12; } .add_adBanner li { margin : 0 0 0 0; padding : 0 0 0 0; border : 0; float : left; } /*이웃추가버튼 추가 종료*/