A. A+B Again?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
Given a two-digit positive integer \(n\), find the sum of its digits.
Input
The first line contains an integer \(t\) (\(1 \leq t \leq 90\)) — the number of test cases.
The only line of each test case contains a single two-digit positive integer \(n\) (\(10 \leq n \leq 99\)).
Output
For each test case, output a single integer — the sum of the digits of \(n\).
题意
给定一个两位数正整数,求其位数之和。
Example
Input
8
77
21
40
34
19
84
10
99
Output
14
3
4
7
10
12
1
18
题解
当时没看到两位数,当普通的求位数和做的
用字符串存起来,遍历每一位求和就好了
代码
#include <bits/stdc++.h>
#define int unsigned long long
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()
int t = 1;
void solve() {
std::string s;
std::cin >> s;
int ans = 0;
for(int i = 0 ; i < s.size() ; i ++) ans += s[i] - '0';
std::cout << ans << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> t;
while(t--) solve();
return 0;
}
标签:964,std,int,题解,leq,test,integer,Div
From: https://www.cnblogs.com/jiejiejiang2004/p/18346789