美文网首页
UVA 1225 Digit Counting

UVA 1225 Digit Counting

作者: iamkai | 来源:发表于2016-11-18 17:50 被阅读0次

Problem

第一個輸入為testcase次數
第二個數字為n代表從1寫到n寫在一起總共有幾個0-9總共出現多少次, example:

  1. n = 3, 123這串數字裡0-9總共出現多少次
  2. n = 13, 12345678910111213這串數字裡0-9總共出現多少次

Solution

// UVa:1225-Digit Counting

#include<iostream>
using namespace std;

int main()
{
    int testcase;
    cin >> testcase;
    
    for(int i = 0 ; i < testcase ; i++)
    {
        int num;
        int count[10] = {0};// 用來計數0-9共有幾個
        cin >> num;
        
        // 計數0-9的數字
        for(int j = 1 ; j <= num ; j++)
        {
            string temp = to_string(j);
            for(int k = 0 ; k < temp.length() ; k++)
                count[temp[k] - '0']++;
        }
        
        //output
        for(int j = 0 ; j < 10 ; j++)
        {
            if(j != 0)
                cout << " ";
            cout << count[j];
        }
        cout << endl;
    }
}

相关文章

  • UVA 1225 Digit Counting

    Problem 第一個輸入為testcase次數第二個數字為n代表從1寫到n寫在一起總共有幾個0-9總共出現多少次...

  • 3-3 数数字(Digit Counting , ACM/ICP

    1225 - Digit Counting 习题3-3 数数字(Digit Counting , ACM/ICPC...

  • UVa1583 Digit Generator -- Java

    我在 github 上建立了一个 repo,专门记录自己对刘汝佳的《算法竞赛入门经典(第二版)》中每个 UVa 例...

  • CH3-UVA1225

    UVA1225 思路 思路很简单, 因为题目说最大输入N,最多不会超过10000, 输入的数据组最多20行.我的思...

  • UVa1225 数数字 习题3-3

    3-3 「UVa1225」数数字: 把前n(n<=1000)个整数顺次写在一起:89101112...数一数09各...

  • grep ip

    egrep '[[:digit:]]{1,3}.[[:digit:]]{1,3}.[[:digit:]]{1,3}...

  • digit Generator

    1583 Digit GeneratorFor a positive integer N, the digit-s...

  • 素数练习题

    UVA 10375 UVA 10791 UVA10375 Choose and divide 题解 先素数打表,然...

  • 相泽三三生日企划

    counting down 5 电台 counting down 4 围巾 counting down 3 烧酒 ...

  • 有趣的数学题

    UVA12716 UVA11582 UVA12716 GCD XOR 题解 参考这题用到2个结论a ^ b = c...

网友评论

      本文标题:UVA 1225 Digit Counting

      本文链接:https://www.haomeiwen.com/subject/gokspttx.html