有没有办法将一系列零作为int输入? [英] Is there a way to take a series of zeros as an int input?

查看:144
本文介绍了有没有办法将一系列零作为int输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重建70年代的老主脑视频游戏。

I'm in the process of recreating the old mastermind video game from the '70s.

用户进行四位数猜测,然后将其记录为向量。

The users makes a four digit guess, which is then logged as a vector.

我知道有一种方法可以接受输入作为一个字符串,但是如果没有办法用一个单独的int输入做到这一点,我会觉得很奇怪 - 我一直无法找到方法。

I know there exists a way to accept the input as a string, however I would find it odd if there isn't a way to do this with one single int input -- which I haven't been able to find a method for.

我目前设置的方式,如果用户提供0003的输入,这将被记录为数字不足的错误,因为int的值是简单地解释为3.并非完全出乎意料,但使用int方法是否真的无法一次取全部四位数?

The way I have it currently set up, if the user provides an input of 0003, this will be logged as an insufficient digit error, as the value of the int is interpreted as simply 3. Not totally unexpected, but is there really no way to take all four digits at once using an int method?

谢谢!

O

/ e
考虑到游戏机制,输入3(数字错误不足)应该是可区分的来自0003的输入;

/e With the game mechanics in mind, an input of 3 (insufficient digit error) should be distinguishable from an input of 0003;

推荐答案

三。 3。 Threeeeeeeeeeeeeeeeee。 03。 003。 0003。 00000000000000003。 III。 3。 11。 3。 三。 Γ'。

"Three". "3". "Threeeeeeeeeeeeeeeeee". "03". "003". "0003". "00000000000000003". "III". "٣". "11". "३". "三". "Γʹ".

上述所有事情有什么共同之处?他们都是三号和匕首的代表;这些陈述有何不同?是。他们代表的数字是不同的吗?没有。只有一个三号。

What do all the above things have in common? They're all representations of the number three†. Are the representations different? Yes. Are the numbers they represent different? No. There is only one number three.

三号与三号无法区分,因为只有一个三号。但是,三个数字的两个表示可能彼此不同,因为它们可能使用不同的符号或不同的规则来将符号组合在一起。

The number three is indistinguishable from the number three as there is only one number three. However, two representations of the number three may be distinct from each other, since they may use different symbols, or different rules for bringing the symbols together.

int 在C ++中(几乎所有具有类似数据类型的语言)都用于处理数字。因此,如果将数字3分配给这种类型的变量,则得到数字3。你没有得到它的任何特定表示。这是第三名。当你要求它时,你会得到它的表示,比如当你输出它时。

ints in C++ (and in pretty much every language with a similar data type) are used to handle numbers. So, if you assign the number three to a variable of such a type, you get the number three. You don't get any particular representation of it. It's the number three. You get a representation of it when you ask for one, like when you output it.

那么,你怎么说出3和0003之间的区别它们代表相同的数字?简单:你不使用数字。

So, how do you tell the difference between "3" and "0003" if they represent the same number? Easy: you don't use numbers.

这里的根本问题是你认为你正在处理数字,但事实并非如此。您关注的是陈述,而不是数字本身。因此,您应该使用可以处理表示的数据类型,而不是可以处理数字的数据类型。我认为最简单的解决方案是使用 std :: string

The fundamental problem here is that you think you are dealing with numbers, but aren't. You are concerned with the representations, not the numbers themselves. So you should use a data type that can handle representations instead of one that can handle numbers. I believe the simplest solution is to use std::string.

&匕首;顺序为:英语,十分之一带有印度 - 阿拉伯数字,英语带有无关的e代表语音中较长的最终声音,八分之一用C表示法,八分之一用C#表示法,附加多余的零,基础八十七印度 - 阿拉伯数字和三个冗余零,基本三十,印度 - 阿拉伯数字和十二个冗余零,罗马数字,东方阿拉伯数字,基数二,印度阿拉伯数字,天城数字,中文数字和希腊数字。

† In order: English, base ten with Indo-Arabic numerals, English with extraneous "e"s to imply a longer final sound in speech, base eight in C notation, base eight in C# notation with an additional redundant zero, base eighty-seven with Indo-Arabic numerals and three redundant zeros, base thirty with Indo-Arabic numerals and twelve redundant zeros, Roman numerals, Eastern Arabic numerals, base two with Indo-Arabic numerals, Devanagari numerals, Chinese numerals, and Greek numerals.

这篇关于有没有办法将一系列零作为int输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆