数数字(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[i] == ‘0‘) a0++;
if (s[i] == ‘1‘) a1++;
if (s[i] == ‘2‘) a2++;
if (s[i] == ‘3‘) a3++;
if (s[i] == ‘4‘) a4++;
if (s[i] == ‘5‘) a5++;
if (s[i] == ‘6‘) a6++;
if (s[i] == ‘7‘) a7++;
if (s[i] == ‘8‘) a8++;
if (s[i] == ‘9‘) a9++;
}
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n", a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
system("pause");
}

时间: 2024-10-21 09:40:44

数数字(Digit Counting,ACM/ICPC Danang 2007,UVa1225)的相关文章

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

思路: 利用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

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

把前n(n<=10000)个整数顺次写在一起:123456789101112-数一数0~9各出现多少次(输出10个整数,分别是0, 1, -, 9出现的次数). #include <stdio.h> #include <string.h> #define maxn 10000 char s[maxn]; int act[10]; int main() { int i; while(scanf("%s", s) == 1){ int len = strlen

UVa 1225 - Digit Counting - ACM/ICPC Danang 2007 解题报告

1.题目大意 把前n$n\le 10000$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更好的办法了,写完看了一下其它人的思路好像也差不多是打表的思路. 3.应注意的问题 (1)首先是格式问题,我第一次提交的时候PE了,因为没有意识到空格也会有影响.最开始我的最后一段代码是: for(i=0;i<10;i++) printf("%d ",s[n][i]); printf(&q

分子量(Molar Counting, ACM/ICPC Seoul 2007, UVa1586)

An organic compound is any member of a large class of chemical compounds whose molecules contain carbon. The molar mass of an organic compound is the mass of one mole of the organic compound. The molar mass of an organic compound can be computed from

最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n(1<=n<=100000), 求最小生成元.无解输出0.例如,n=216,121,2005时的解分别是198,0,1979. Think 方法一:假设所求生成元记为m,不难发现m<n.换句话说,只需枚举所有的m<n,看看有木有哪个数是n的生成元.此举效率不高,因为每次计算一个n的生成元

生成元(Digit Generator,ACM/ICPC Seoul 2005, UVa1583)

For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M . For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of

分子量 (Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)

解题思路: 1.将分子量用double 数组记录下来 2.将字符串存储在字符数组中,从头向后扫描,一直记住“字母”,对下一个字符进行判断,是否是数字,如果是数字:用一个整数记录,本代码中用的sum,同时下标++. 进行判断,查看是否对数字进行了记录,即查看sum是否进入了while循环并被赋值,如果没有被赋值,说明下一个字符不是数字,直接对W(总记录)值进行赋值,为当前字符的权值(分子量),即double数组的中的值.如果被赋值,说明字符后面是一个数字,sum中存放了该“数字”,也是对w赋值,不

Digit Generator, ACM/ICPC Seoul 2005, UVa1583

For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N, we call N a generator of M. For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of 256

【紫书】例题3-5 生成元(Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

[题目描述] 如果x加上x的各个数字之和得到y,就说x是y的生成元.给出n(1≤n≤100000),求最小生成元.无解输出0.例如,n=216,121,2005时的解分别为198,0,1979. [代码实现] 方法1 1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 int main() 7 { 8 int n = 0; 9 while ( scanf ("%d", &a