X 位数的最大数量 [英] Max number of X digits number
本文介绍了X 位数的最大数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找关于当整数达到其数字的最大数时停止的条件的想法..
I am looking for an idea about a condition that stop when an integer reach to the max number of its digit..
即
2 位数字的最大数目为 99
the max number of 2 digits number is 99
5 位数字的最大数目为 99999
the max number of 5 digits number is 99999
我有这个
while(x != ([10^number of digits] -1))
{
x++;
}
cout << x;
但实际上我正在处理字符串,它可能有一个巨大的数字,并且这段代码在 9 位数后开始执行很长的时间.
but actually i am dealing with string, which may i have a huge numbers, and this code start to get very long execution time after 9 digits.
谁能给我一个好主意,谢谢.
So can any one give me a good idea about that, Thanks.
推荐答案
怎么样:
done = false;
while(!done)
{
x++;
done = true;
for (i=0 ; i<number_of_digits; i++)
if x[i] != '9'
done = false;
}
cout << x;
这篇关于X 位数的最大数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文