作者tarjan (Mr. Everything)
看板C_Sharp
标题Re: [问题] 数字被吃一位?
时间Tue Oct 6 14:58:39 2009
※ 引述《Fnd (劝君莫回首)》之铭言:
: 请问,我写
: static void Main(string[] args)
: {
: int i, x, y;
: while (Console.Read() != 0)
: {
: x = int.Parse(Console.ReadLine());
: Console.Write(x);
: }
: }
: 时,为何他会吃掉最前面一位数呢?
: ex:12345会跑出2345= =a
: 抱歉第一次使用c sharp问题有点noob...
由原文看起来似乎是要限定第一个数字不能是0?
如果是的话可以这样作
static void Main(string[] args)
{
string x;
int y;
while ((y=Console.Read()) != -1)
{
x = Console.ReadLine();
if (y != 48)
x = Convert.ToChar(y) + x;
Console.WriteLine(x);
}
}
input: 028
ouput: 28
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 60.249.154.130
1F:推 Fnd:感谢您的回答,kinwind先生已经替我解惑罗^^ 10/07 02:21