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 to N (1 < N < 10000). After that, he counts the number of times each digit (0 to 9) appears in the seque…
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…
题目连接: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…
思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. 13 string=12345678910111213 carr[1]++.carr[2]++.carr[3]++....carr[1]++.carr[1]++.carr[1]++.carr[2]++.carr[1]++.carr[3]++ AC Code: import java.util.Sc…
题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ]; int main() { int ncase,n,i; scanf("%d",&ncase); wh…
1.题目大意 把前n$(n\le 10000)$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更好的办法了,写完看了一下其它人的思路好像也差不多是打表的思路. 3.应注意的问题 (1)首先是格式问题,我第一次提交的时候PE了,因为没有意识到空格也会有影响.最开始我的最后一段代码是: for(i=0;i<10;i++) printf("%d ",s[n][i]); printf(…
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000) . After that, he counts the number of times each digit (0 to 9) appears in the sequen…
#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)  …
#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[…
大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long LL; ; LL n,A[MAXN]; int main() { A[] = ; ;i<MAXN;i++) A[i] = A[i-] + ((i-)*(i-)/ - (i-)/)/; while(cin>>n && n) { ) break; cout<<A[n]…