《ACM程序设计》书中题目U(美丽数字)
来源:互联网 发布:js时间戳与php时间戳 编辑:程序博客网 时间:2024/06/07 09:18
Description
Mike is very lucky, as he has two beautiful numbers, 3 and 5. But he is so greedy that he wants infinite beautiful numbers. So he declares that any positive number which is dividable by 3 or 5 is beautiful number. Given you an integer N (1 <= N <= 100000), could you please tell mike the Nth beautiful number?
Input
The input consists of one or more test cases. For each test case, there is a single line containing an integer N.
Output
For each test case in the input, output the result on a line by itself.
Sample Input
1
2
3
4
Sample Output
3
5
6
9
题目大意是麦克想要美丽数字,而美丽数字就是可以被3或5整除的正数;
思路如下:
1.建立美丽数字数据库;
2.输入n(第几个),查找;
#include<bits/stdc++.h>using namespace std;int main(){ vector<int> a; int i,n,k; for(i=1,k=0;k<=100000;i++) { if(i%3==0||i%5==0) { a.push_back(i); k++; } } while(cin>>n) cout<<a[n-1]<<endl;}题目毫无难度,但是有一个陷阱,要求是10 0000个以内的美丽数字,而不是10 0000以内的美丽数字,这一点没有注意的话,会导致越界的错误。
0 0
- ACM程序设计 书中题目U(美丽的数字)
- 《ACM程序设计》书中题目U(美丽数字)
- 《ACM程序设计》书中题目--problem u
- 《ACM程序设计》书中题目 U
- 《ACM程序设计》书中题目―U
- 《ACM程序设计》书中题目U
- 《ACM程序设计》书中题目 U
- 《acm程序设计》书中题目U-21
- 《ACM程序设计》书中题目 U
- 《ACM程序设计》-Problem-U-第N个美丽数字
- 《ACM程序设计》书中题目U 第二十一题 漂亮的数字
- 《ACM程序设计》书中题目W(让草坪变美丽吧,Tom!)
- 《ACM程序设计》书中题目 N-14 颠倒数字相加
- ACM程序设计 书中题目N(翻转数字)
- ACM程序设计书中题目--N(数字反转)
- acm程序设计书中的题目u
- 《ACM书中题目》 U
- 《ACM程序设计》书中题目
- 判断两个链表是否存在交点 并求出位置
- Django在网页显示本地静态资源
- gradle编译启动项目时报错Could not find tools.jar
- iOS本地化学习小结
- 向Retrofit打响第一炮
- 《ACM程序设计》书中题目U(美丽数字)
- 二叉树的遍历算法实现、以及所有简单操作
- MVPExample--Android MVP开发见解
- 安装和使用Karma-Jasmine进行自动化测试
- 海航持续并购正向发展,集团破产消息是假的
- Spark RDD持久化策略
- java 学习总结
- Fundebug上线Node.js错误监控啦
- 初探匿名内部类