문제) Codeforces - 구현 - A) Countdown
https://codeforces.com/contest/1573/problem/A
Problem - A - Codeforces
codeforces.com
맨 끝자리가 아닐 경우, cnt를 하나씩 증가시키면서 자릿수를 더해 나간다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define endl "\n" | |
#define ll long long | |
#define INF 987654321 | |
#define MAX 10001 | |
#define MOD 1000000000 | |
using namespace std; | |
typedef pair<int, int> p; | |
signed main() { | |
int tc; cin >> tc; | |
while (tc--) { | |
int cnt = 0; | |
int n; cin >> n; | |
string s; cin >> s; | |
for (int i = 0; i < n; ++i) { | |
if (s[i] == '0') | |
continue; | |
else { | |
cnt += (s[i] - '0'); | |
if (i != n - 1) | |
cnt++; | |
} | |
} | |
cout << cnt << endl; | |
} | |
return 0; | |
} |
반응형
'PS(Problem Solving) > ETC' 카테고리의 다른 글
[Code Jam] 2021 Code Jam 도전! (0) | 2021.03.27 |
---|---|
[Algorithm] 위상 정렬 - Topology Sort (파이썬, C++) (0) | 2021.03.10 |
[Python] sort( ), sorted( ), lambda (0) | 2021.02.27 |
댓글