codeforces1553A. Digits Sum

题目如下
A. Digits Sum
time limit per test1 second
memory limit per test256 megabytes
Let's define 𝑆(𝑥) to be the sum of digits of number 𝑥 written in decimal system. For example, 𝑆(5)=5, 𝑆(10)=1, 𝑆(322)=7.

We will call an integer 𝑥 interesting if 𝑆(𝑥+1)<𝑆(𝑥). In each test you will be given one integer 𝑛. Your task is to calculate the number of integers 𝑥 such that 1≤𝑥≤𝑛 and 𝑥 is interesting.

Input
The first line contains one integer 𝑡 (1≤𝑡≤1000) — number of test cases.

Then 𝑡 lines follow, the 𝑖-th line contains one integer 𝑛 (1≤𝑛≤109) for the 𝑖-th test case.

Output
Print 𝑡 integers, the 𝑖-th should be the answer for the 𝑖-th test case.

题目大意
题目定义了S(x)的意义是x的各项和,定义了有趣数满足 𝑆(𝑥+1)<𝑆(𝑥)的条件,让我们求出不大于每组样例所给n的所有数中有趣数的个数

题目分析
若要满足 𝑆(𝑥+1)<𝑆(𝑥),例如S(9)=9,S(9+1)=S(10)=1满足条件,而在1到9中只有9满足,同样我们发现,99,199,2999,99999···也同样满足这样的规律,而只要满足最后一位是9的数均能满足有趣数的条件,所以

点击查看代码
#include <stdio.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d", &n);
        int sum = n / 10;
        if(n % 10 == 9)
            sum++;
        printf("%d\n", sum);
    }
    return 0;
}
posted @ 2025-07-02 21:28  sirro1uta  阅读(14)  评论(0)    收藏  举报