Print the numbers of form 2^i.5^j in increasing order -- Google
2013-07-04 11:30
399 查看
Problem
Print the numbers of form 2^i.5^j in increasing order. For eg:
1, 2, 4, 5, 8, 10, 16, 20
Solution
Output
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]Find numbers of nodes in a BST in the range [low,high]
- [Google] print the outline of a complete binary tree in anti-clockwise direction
- Exchange the numbers of row and array of a two-dimensional array, and form a new two-dimensional ar
- The sum of numbers form 0 to n.(20.9.2017)
- Get all the coordinates of listed banks from Google Maps with Python 3
- Bringing the power of Google technology to mobile
- PAT-B 1019. 数字黑洞(同PAT 1069. The Black Hole of Numbers)
- How to print the content of a Rich Edit Control
- 『ORACLE』Error ocurred while retrieving node numbers of the existing nodes.(11g)
- Problem 11 of What is the greatest product of four adjacent numbers
- chrome视频无法播放的解决方法(Solve the problem of Google player cannot be played normally)
- 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise
- RFC1219-- On the Assignment of Subnet Numbers
- PAT (Advanced Level) 1069. The Black Hole of Numbers (20) 简单数字操作
- View the format of IEEE 754 floating point numbers source code
- pat-a1069. The Black Hole of Numbers (20)
- The encryption certificate of the relying party trust identified by thumbprint is not valid
- [PAT-甲级]1069.The Black Hole of Numbers
- bpel 测试遇到“The content of the body cannot be displayed in the form view. Please switch to the source”