UVA1225 UVALive3996 Digit Counting

Regionals 2007 >> Asia - Danang

问题链接:UVA1225 UVALive3996 Digit
Counting
。入门练习题,用C语言编写程序。

这个问题是数字出现次数统计问题,按照套路处理就可以了。

本程序的套路包括,用运算符%从整数中取出数字,输出格式控制。

AC的C语言程序如下:

/* UVA1225 UVALive3996 Digit Counting */

#include <stdio.h>
#include <memory.h>

#define DIGITNUM 10

int ans[DIGITNUM];

int main(void)
{
    int t, n, val, i;

    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);

        memset(ans, 0, sizeof(ans));

        for(i=1; i<=n; i++) {
            val = i;
            while(val) {
                ans[val % 10]++;
                val /= 10;
            }
        }

        for(i=0; i<DIGITNUM; i++) {
            if(i)
                putchar(' ');
            printf("%d", ans[i]);
        }
        putchar('\n');
    }

    return 0;
}
时间: 2024-07-29 21:05:57

UVA1225 UVALive3996 Digit Counting的相关文章

UVa 1225 / UVALive 3996 Digit Counting 数数字(字符统计)

Digit Counting Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting

UVa1587.Digit Counting

题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&page=show_problem&problem=3666 13764622 1225 Digit Counting Accepted C++11 0.035 2014-06-18 07:44:02 1225 - Digit Counting Time limit: 3.000 seconds Tru

UVa 1225 Digit Counting --- 水题

UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现的次数,先将cnt初始化为0,接着让i从1枚举到n, 对每个i,处理以活的i的每一个位置上的数,并在相应的cnt下标上+1 最后输出cnt数组即可 /* UVa 1225 Digit Counting --- 水题 */ #include <cstdio> #include <cstring

UVA 1225 Digit Counting(统计数位出现的次数)

Digit Counting Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu SubmitStatus Description Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting

UVa-1225 Digit Counting(数数字)

对于一个大于1且小于10000的整数N,我们定义一个唯一与之相关联的序列.例如,若N为13,则该序列为12345678910111213.现要求对于一个输入值N,记录这个序列中每个数字出现了多少次. 输入格式:先是一个整数以表明要输入的整数个数,之后每行给出一个大于1且小于10000的整数. 输出格式:每行输出每个数字出现的个数.如果输入为13,那么输出为1 6 2 2 1 1 1 1 1 1. 具体见https://cn.vjudge.net/problem/uva-1225 思路:没有多加思

UVa1225 Digit Counting

#include <stdio.h>#include <string.h> int main(){    int T, N, i, j;    int a[10];    scanf("%d", &T);    while (T--)    {        memset(a, 0, sizeof(a));        scanf("%d", &N);        for (i = 1; i <= N; ++i)  

数数字(Digit Counting,ACM/ICPC Danang 2007,UVa1225)

#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[10000]; int a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0; scanf("%s", s); for (int i = 0; i < strlen(s); i++) { if (s[

紫书第三章练习题:UVA 1225 Digit Counting by 15邱盼威

来源:http://m.blog.csdn.net/article/details?id=70861055 Trung is bored with his mathematicshomeworks. He takes a piece of chalk and starts writing a sequence ofconsecutive integers starting with 1 to N (1 < N < 10000). After that, hecounts the number

Digit Counting UVA - 1225

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