首页 > 其他分享 >题解:Codeforces Round 964 (Div. 4) A

题解:Codeforces Round 964 (Div. 4) A

时间:2024-08-07 12:07:14浏览次数:6  
标签:964 std int 题解 leq test integer Div

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

相关文章

  • 【题解】Solution Set - NOIP2024集训Day1 数据结构
    【题解】SolutionSet-NOIP2024集训Day1数据结构https://www.becoder.com.cn/contest/5429「CF1428F」FruitSequences线段树是可以维护区间最长子段的1。记固定右端点在\(i\),的答案为\(f_i\)。那么:\(a_i=0\),\(f_i=f_{i-1}\);\(a_i=1\),打一个单调栈维护所有的最长子......
  • 题解:P10543 [THUPC 2024 决赛] 黑白
    好题。题意\(n\timesm\)的网格图初始每个格子有黑有白,两人轮流操作,每次选择一个白格染黑。操作后不能存在一条\((1,1)\)到\((n,m)\)的路径,否则本次操作者输,另一人赢。思路首先判断是否一上来就输了。易发现到最后一定会操作到只剩一条道路,设路径长度为\(s\),那么\(s\)......
  • 题解:UVA11181 条件概率 Probability|Given
    主要思路:概率期望。首先可以发现\(n\)的数据极小。然后我们设\(a\)为为每个人买东西的情况,\(b\)为当有\(b\)个人去时的情况。大家都应该知道条件概率式子为\(P(a|b)=\frac{P(ab)}{P(b)}\)。然后暴力搜索\(P(ab)\)和\(P(b)\)。其实这道题有复杂度更低的dp做法,但......
  • 题解:CF1896G Pepe Racing
    主要思路:构造。思路方法一一个一个的找,分别查询\([1,n],[n+1,2n],\dots,[n(n-1)+1,n^{2}]\)中最快的人,再把\(n\)个人合起来查询,不过很明显的是,这个方法很蠢,并不能切掉此题。方法二找第二快的人,只有最快的人在的一组需重新询问,剩下答案无需改变。需排除的人的一组用不是现......
  • Codeforces Round 964 (Div. 4) 补题记录(A~G2)
    难绷事实:Bwa一发A......#include<bits/stdc++.h>#definepbpush_back#defineintlonglongusingnamespacestd;constintN=500100;inta[N];signedmain(){intT;cin>>T;while(T--){intn;cin>>n;strings=......
  • Codeforces Round 964 (Div. 4)
    CodeforcesRound964(Div.4)A计算数位和。voidsolve(){ inta=0,n; cin>>n; while(n)a+=n%10,n/=10; cout<<a<<'\n';}B模拟,直接枚举4种出牌顺序,按题目给的规则判断即可。boolchk(intx1,inty1,intx2,inty2){ intc1=(x1&g......
  • 2024牛客暑期多校训练营7 C Array Sorting 题解
    乱搞非正解写法。分类讨论各种情况。降序排序对应交换即可数组个数小直接考虑相邻的交换其他都看做随机数据考虑结合前面情况,很容易想到,先把数组变成一个尽量有序的数组(每个元素和自己正确的位置相差不大)。最后再多次相邻交换,使得每个元素都在正确位置。把数组变成......
  • 洛谷 P4910题解
    题目大意现在穿T次手串,每根手串的长度分别为不同的n,有木和金两种珠子,相邻两颗珠子必须有一个是金。题目思路分析我们现在设穿到第n个珠子时用金的方案数为f[1][n],用木的方案数为f[0][n]如果第n个珠子为金,那么前一颗珠子是什么都可以,因此f[1][n]=f[1][n-1]+f[0][n-1]而如果......
  • CF573E Bear and Bowling 题解
    Description给定一个长度为\(n\)的序列\(a_{1\dotsn}\)。你要求一个\(a\)的子序列\(b_{1\dotsm}\)(可以为空),使得\(\sum_{i=1}^mib_i\)的值最大。\(n\le10^5\),\(|a_i|\le10^7\)。Solution有一个显然的dp是设\(f_{i,j}\)表示前\(i\)个数,选\(j\)个数的......
  • CF1920D题解
    题面这里不再赘述了,直接搬个链接。InLuoguInCodeforces思路存储一共两种操作:要么在末尾加一个数xxx,要么把整一段复制......