poj 3720(Occurrence of Digits)
来源:互联网 发布:手机淘宝卖家版登陆 编辑:程序博客网 时间:2024/06/06 01:22
#include<stdio.h>#include<stdlib.h>#include<string.h>int c[20],a[200];int main(){int i,p,j,x,y,m,n,s,flag;while(scanf("%d%d",&x,&y)!=EOF){memset(c,0,sizeof(c)); for(i=2;i<=x;i++) { flag=1; p=10; memset(a,0,sizeof(a)); s=1; while(flag) { m=p/i; n=p%i; a[s++]=p; if(n==0) { c[m]++; flag=0; break; } else { c[m]++; p=n*10; for(j=1;j<s;j++) { if(a[j]==p) { flag=0; break; } } } } } printf("%d\n",c[y]);}return 0; }
算法老师留的作业题,是加了星号的,确实有点难度,wa了3次,第四次才AC的,题意挺好理解的,就是求一个数出现的次数,难点就在表示出循环体,我是用被除数判断的,如果重复出现了被除数,那就证明循环体出现了。用来记录数字出现的次数我用了一个数组来表示,比如说c[m]++就说明m出现了,c[m]里存的就是m出现的次数,用的变量比较多,而且是随意定义的,可能看不下去,不太好理解
放代码
0 0
- poj 3720(Occurrence of Digits)
- 【POJ】3720 Occurrence of Digits
- poj 3720 Occurrence of Digits
- POJ Occurrence of Digits
- POJ 3720 Occurrence of Digits 可能会
- POJ-3720(分数的小数表示,只要循环节)(Occurrence of Digits)
- poj3720——Occurrence of Digits//循环节
- Total Occurrence of Target
- Occurrence
- The First Occurrence of Needle In Haystack
- POJ 3531 Alternating Sum of Digits 英文少
- 993 - Product of digits(贪心)
- URAL1658 Sum of Digits(DP)
- 【LightOJ】1045 - Digits of Factorial(数论)
- Lightoj 1045 (Digits of factoria)
- LOJ 1045 - Digits of Factorial(数学)
- lightoj 1045 Digits of Factorial (数学)
- POJ 3373 Changing Digits(DP)
- java 堆栈的区别
- Java SE 第十一讲(面向对象之封装) 续二
- 这段时间装SDK装到吐血
- HDU 1024 — Max Sum Plus Plus
- 不变模式(Immutable Pattern)分析
- poj 3720(Occurrence of Digits)
- Spring 系列: Spring 框架简介(三)
- 类似于歌词滚动的自定义View
- Sicily 1346. 金明的预算方案
- 正则表达式的汉字匹配
- 【星期三过完啦】PHP第七天
- 十五
- linux经典面试题
- tomcat7 内存配置修改方法