본문 바로가기
PS(Problem Solving)/ETC

[Codeforces] Codeforces Round #743 (Div. 2) - A) Countdown (C++) 문제 및 풀이

by 초코칩프라푸치노 2021. 9. 29.

문제) Codeforces - 구현 - A) Countdown

https://codeforces.com/contest/1573/problem/A

 

Problem - A - Codeforces

 

codeforces.com

 

맨 끝자리가 아닐 경우, cnt를 하나씩 증가시키면서 자릿수를 더해 나간다.

 

 

C++ 소스코드)

#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;
}
view raw 743-A.cpp hosted with ❤ by GitHub

 

반응형

댓글