不要62
来源:互联网 发布:怎样在淘宝上买论文 编辑:程序博客网 时间:2024/05/22 00:29
不要62
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21067 Accepted Submission(s): 7197
Problem Description
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
Input
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
Output
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
Sample Input
1 1000 0
Sample Output
80源代码一:解题思路:采用打表法和char *itoa(int value, char *string, int radix)整型转换为字符 串的函数#include<stdio.h>#include<string.h>#include<stdlib.h>int a[1000010];int main (){ int count,sum,i,j,m,n,k,l; char s[10]; for(i=1;i<1000010;i++)//新的函数 { itoa(i,s,10); /* char *itoa(int value, char *string, int radix); int value 被转换的整数, char *string 转换后储存的字符数组, int radix 转换进制数,如2,8,10,16 进制等 头文件:#include<stdilib.h> */ l=strlen(s); count=0; for(j=0;j<l;j++) { if(s[j]=='4') { count++;break; }//break;跳过了一个数种含多个4的可能; if(s[j]=='6'&&s[j+1]=='2') { count++;break; }//对一个数里同时出现62 * 4; } a[i]=count; } while(scanf("%d%d",&n,&m)!=EOF&&(n||m)) { sum=0; for(i=n;i<=m;i++) sum=sum+a[i]; printf("%d\n",m-n-sum+1); } system("pause"); return 0;}源代码二:#include<iostream>using namespace std;int main(){ int n,m; bool bs[1000010]; memset(bs,0,sizeof(bs)); int temp; for(int i=1;i<=1000001;i++) { int sum=temp=i; while(temp>0) { if(temp % 10 == 4 || temp % 100 == 62) bs[sum]=1; temp=temp/10; } } while(cin>>n>>m && (n||m)) { int count=m-n+1; for(int i=n;i<=m;i++) { if(bs[i]==1) count--; } cout<<count<<endl; } system("pause"); return 0;}
0 0
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 中文 iOS/Mac 开发博客列表
- dataGridView 表头 边框颜色
- solr进阶三:从数据库中导入数据到solr
- gallery解决快速滑动以及滑动距离过宽的问题
- The Swift Programming Language--语言指南--构造过程
- 不要62
- ClickOnce部署 II - 应用程序部署
- C语言中关于.h和.c的问题
- 0090 Java线程:Timer和TimerTask【基础】
- Binary Tree Postorder Traversal 二叉树的后序遍历,使用堆栈,非递归
- js 获取Gridview textbox 值的问题
- Android权限大全
- 低内存管理lower memory killer
- 关于android SDK更新报错Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml