Print the numbers of form 2^i.5^j in increasing order -- Google
来源:互联网 发布:tk免费域名官网 编辑:程序博客网 时间:2024/06/05 11:15
Problem
Print the numbers of form 2^i.5^j in increasing order. For eg:
1, 2, 4, 5, 8, 10, 16, 20
Solution
using System;
using System.Collections.Generic;
namespace JamesChen
{
class PrintNumIncreasingly
{
static void PrintIncreasingNums(int n)
{
if (n < 0) return;
List<int> a = new List<int>();
a.Add(1);
int count2 = 0;
int count5 = 0;
while (a.Count < n)
{
if (a[count2] * 2 < a[count5] * 5)
{
a.Add(a[count2] * 2);
count2++;
}
else if (a[count2] * 2 > a[count5] * 5)
{
a.Add(a[count5] * 5);
count5++;
}
else
{
a.Add(a[count5] * 5);
count2++;
count5++;
}
}
foreach (var i in a)
{
Console.Write("{0, 6}", i);
}
Console.WriteLine();
}
static void Main(string[] args)
{
PrintIncreasingNums(20);
}
}
}
Output
1 2 4 5 8 10 16 20 25 32 40 50 64 80 100 125 128 160 200 250
Press any key to continue . . .
- Print the numbers of form 2^i.5^j in increasing order -- Google
- Can I change the order of items in category views?
- [Google] print the outline of a complete binary tree in anti-clockwise direction
- [Google]Find numbers of nodes in a BST in the range [low,high]
- 逆序输出字符串 print the array in reverse order
- print 'welcome to masm!' in the center of the screen.
- Increasing the maximum number of tcp/ip connections in linux
- Changing the Title of a Print Dialog in Delphi
- Ch4.5: find the (in-order tranversely) successor of a node in BST.
- LINTCODE——Number of Subsequences of Form a^i b^j c^k
- lintcode 734. Number of Subsequences of Form a^i b^j c^k
- Sort Stack in increasing/decreasing Order.
- Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- The order of items in struts-config.xml
- The study of Higher-order function in Python(20170913)
- Compute the maximal length of the increasing subsequence in an array
- Print an array in spiral order -- Microsoft
- win32多线程编程
- 学习笔记12 ORA-00904 plsql无效标识符 却明明有的字段
- Hadoop 类Grep源代码注释
- js实现按钮点击60秒后重新启用(重新发送验证码)
- jquery事件机制扩展插件 jquery鼠标右键事件
- Print the numbers of form 2^i.5^j in increasing order -- Google
- cocos2d-x lua之创建剪切精灵
- 史上最经典的Linux内核学习方法论
- Spring配置项<context:annotation-config/>解释说明
- 高级进程间通信
- 手动设置Centos静态地址
- class_create
- SVN修改用户名与密码
- 收集的有关网络安全的常用链接