| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 931 人关注过本帖
标题:一道ACM题:The Counting Problem
只看楼主 加入收藏
bupo
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-8-19
收藏
 问题点数:0 回复次数:1 
一道ACM题:The Counting Problem

题目如下:

The Counting Problem
Submit: 57 Accepted:18
Time Limit: 3000MS Memory Limit: 65536K

Description
Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be
1024 1025 1026 1027 1028 1029 1030 1031 1032
there are ten 0s in the list, ten 1s, seven 2s, three 3s, and etc.


Input
The input consists of up to 500 lines. Each line contains two numbers a and b where 0 < a, b < 100000000. The input is terminated by a line “0 0”, which is not considered as part of the input.


Output
For each pair of input, output a line containing ten numbers separated by single spaces. The first number is the number of occurrences of the digit 0, the second is the number of occurrences of the digit 1, etc.


Sample Input

1 10
44 497
346 542
1199 1748
1496 1403
1004 503
1714 190
1317 854
1976 494
1001 1960
00


Sample Output

1 2 1 1 1 1 1 1 1 1
85 185 185 185 190 96 96 96 95 93
40 40 40 93 136 82 40 40 40 40
115 666 215 215 214 205 205 154 105 106
16 113 19 20 114 20 20 19 19 16
107 105 100 101 101 197 200 200 200 200
413 1133 503 503 503 502 502 417 402 412
196 512 186 104 87 93 97 97 142 196
398 1375 398 398 405 499 499 495 488 471
294 1256 296 296 296 296 287 286 286 247
下面是我的代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define END "00"

long int a[500][2]={0};

void change(char x[],int j )//把读取的字符窜转化成一组数 存入a[500][2]中
{
int m=0,n=0;
int i=0;
while(x[i]!=32)
{
m=m*10+(x[i]-'0');
i++;
}
i++;
while(x[i]!='\0')
{
n=n*10+(x[i]-'0');
i++;
}
a[j][0]=m;
a[j][1]=n;
}

void calculate(long int a,long int b)//计算每一组数的结果 并打印之
{
long int i,j;
long int temp;
long int num;
long int result[10]={0};

if(a<=b)
{
for(i=a;i<=b;i++)
{
num=i;
while(num!=0)
{
temp=num%10;
num=num/10;
result[temp]++;
}
}
}
else
{
for(i=b;i<=a;i++)
{
num=i;
while(num!=0)
{
temp=num%10;
num=num/10;
result[temp]++;
}
}
}
for(i=0;i<10;i++)
printf("%d ",result[i]);
}

int main()
{
int sum=0;//计算输入的测试数据的数量
long int i=0;
char c[20];//存放每一行输入的字符窜
gets(c);
while(strncmp(c,END,2))
{
change(c,sum);
gets(c);
sum++;
}
for(i=0;i<sum;i++)
{
calculate(a[i][0],a[i][1]);
printf("\n");
}
system("pause");
return 0;
}

测试了很多组数据都没错,但是一提交就RUNNING ERROR
那位朋友帮帮忙,谢谢

搜索更多相关主题的帖子: Counting ACM Problem The 
2007-08-19 22:35
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
这样做即使不RE
也要TLE
这个题目用第归或者直接第推的LOG(N);

2007-08-20 01:13
快速回复:一道ACM题:The Counting Problem
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015619 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved