1225:Digit Counting

45 篇文章 0 订阅
44 篇文章 0 订阅

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequenceof consecutive integers starting with 1 to N (1 < N < 10000). After that, he counts the number oftimes each digit (0 to 9) appears in the sequence. For example, with N = 13, the sequence is:

12345678910111213

  In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and eachdigit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants towrite a program to do this for him. Your task is to help him with writing this program.

Input

The input file consists of several data sets. The first line of the input file contains the number of datasets which is a positive integer and is not bigger than 20. The following lines describe the data sets.For each test case, there is one single line containing the number N.

Output

For each test case, write sequentially in one line the number of digit 0, 1, . . . 9 separated by a space.

Sample Input

2

3

13

Sample Output

0 1 1 1 0 0 0 0 0 0

1 6 2 2 1 1 1 1 1 1


Regionals 2007 >> Asia - Danang

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define maxn 10000 + 5
int cnt[10];
int main(){
    int i,T,n,num;
    scanf("%d",&T);
    while(T--){
        memset(cnt,0,sizeof(cnt));
        scanf("%d",&n);
        for(i = 1;i <= n;i++){
            int num = i;
            while(num){
                cnt[num%10]++;
                num /= 10;
            }
        }
        for(i = 0;i < 9;i++) printf("%d ",cnt[i]);
        printf("%d\n",cnt[9]);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个使用Tkinter库编写的井字棋游戏的部分代码,其中: 1. `mark = ''`:定义一个变量mark,用于记录玩家的标记,初始值为空。 2. `count = 0`:定义一个变量count,用于记录玩家进行的步数,初始值为0。 3. `panels = ["panel"] * 10`:定义一个列表panels,包含10个元素,初始值为字符串"panel",用于记录井字棋盘面的状态。 4. `def win(panels, sign):`:定义一个名为win的函数,用于判断玩家是否胜利。该函数接受两个参数:panels表示井字棋盘面的状态,sign表示玩家的标记('X'或'O')。函数返回布尔值True或False,表示当前玩家是否胜利。 5. `def checker(digit):`:定义一个名为checker的函数,用于检查玩家点击的按钮,并在井字棋盘面上显示玩家的标记。该函数接受一个参数digit,表示玩家点击的按钮编号。 6. `global count, mark, digits`:声明count、mark和digits为全局变量,表示在函数内部可以访问和修改这些变量。 7. `if digit == 1 and digit in digits:`:如果玩家点击的按钮编号为1并且该数字在数字列表digits中,则执行以下操作。 8. `digits.remove(digit)`:从数字列表digits中删除玩家点击的按钮编号。 9. `if count % 2 == 0:`:如果count是偶数,则表示当前是玩家1的回合。 10. `mark = 'X'`:将玩家1的标记设置为'X'。 11. `panels[digit] = mark`:将井字棋盘面中对应位置的值设置为玩家的标记。 12. `elif count % 2 != 0:`:如果count是奇数,则表示当前是玩家2的回合。 13. `mark = 'O'`:将玩家2的标记设置为'O'。 14. `panels[digit] = mark`:将井字棋盘面中对应位置的值设置为玩家的标记。 15. `button1.config(text=mark)`:将按钮1的文本设置为玩家的标记。 16. `count = count + 1`:将玩家的步数加1。 17. `sign = mark`:将当前玩家的标记赋值给sign。 18. `if (win(panels, sign) and sign == 'X'):`:如果玩家1胜利,则执行以下操作。 19. `msg.showinfo("结果", "玩家1 获胜")`:弹出一个消息框,显示玩家1获胜。 20. `root.destroy()`:销毁窗口,结束游戏。 21. `elif (win(panels, sign) and sign == 'O'):`:如果玩家2胜利,则执行以下操作。 22. `msg.showinfo("结果", "玩家2 获胜")`:弹出一个消息框,显示玩家2获胜。 23. `root.destroy()`:销毁窗口,结束游戏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值