티스토리 뷰
- 자릿수의 합
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int digit_sum(int x){
int tmp, sum=0;
while(x>0){
tmp = x%10;
sum += tmp;
x = x/10;
}
return sum;
}
int main() {
// freopen("input.txt", "rt", stdin);
int n, num, i, sum, max=-2147000000, res;
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &num);
sum = digit_sum(num);
if(sum > max){
max = sum;
res = num;
}
else if(sum == max){
if(num > res){
res = num;
}
}
}
printf("%d\n", res);
return 0;
}
- 숫자의 총 개수
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
//freopen("input.txt", "rt", stdin);
int n, i, cnt=0;
scanf("%d", &n);
for(i=1; i<=n; i++){
int tmp=i; // for문에서 i인덱스로 돌고있을 때 i를 변경시켜선 안됨
while(tmp>0){
tmp = tmp/10;
cnt++;
}
}
printf("%d\n", cnt);
return 0;
}
'algorithm' 카테고리의 다른 글
[c++] 뒤집은 소수, 소수의 개수 (0) | 2020.12.01 |
---|---|
[c++] 숫자의 총개수, 가장 많이 사용된 자리수 (0) | 2020.11.30 |
[c++] 모두의 약수 (0) | 2020.11.28 |
[c++] 공백없애기, 올바른 괄호 (0) | 2020.11.27 |
나이차이, 나이계산, 숫자만추출 (0) | 2020.11.26 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 동적프로그래밍
- react
- 입출력장치
- C
- Stack
- 운영체제
- C++
- 병행프로세스
- 배열
- 최단경로
- 교착상태
- 세마포어
- 퀵정렬
- Java
- 스텍
- 자료구조
- 클래스
- 알고리즘
- 이진탐색
- client side rendering
- 구조체
- 인접리스트
- javascript
- server side rendering
- dfs
- 소프트웨어
- 재귀함수
- stackframe
- BFS
- 인접행렬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함