如何将数字写为代码? [英] how can I write numbers as codes?
问题描述
你好伙伴们,
我正在尝试编写游戏用户将随机点击7个按钮,每个按钮存储整数变量的点击次数。
int button1TOTAL ++;
int button2TOTAL ++;
...
...
int button7TOTAL ++;
之后我想要对这些从大到小的整数中收集的3个进行排序将它们命名为
例如:
用户按下按钮:10,1,2,4,6 ,5,3次
排序后
10> 6> 5
如果数字10等于button2TOTAL计数,则数字10应写入A
如果数字6等于button4TOTAL计数,则数字6应写为N
如果数字5与button7TOTAL计数相等,则数字5应写入D
它应该是:
AND
我有七个字符{A,D,T,N,Y,E,P},有7.6.5个可能性!我怎么能很快解决这个问题?
Hello fellows,
I'm trying to write a game user will click 7 buttons randomly and each buttons stores the count of clicks in integer variable.
int button1TOTAL ++;
int button2TOTAL ++;
...
...
int button7TOTAL ++;
after that I want to sort collected 3 of these integers largest to smallest and name them
for example:
user pushes buttons : 10,1,2,4,6,5,3 times
after sorted
10>6>5
if number 10 is equal with button2TOTAL count, number 10 should write "A"
if number 6 is equal with button4TOTAL count, number 6 should write "N"
if number 5 is equal with button7TOTAL count, number 5 should write "D"
it should be seemed:
"AND"
I have seven chars {A,D,T,N,Y,E,P} and there is 7.6.5 possibilites!! how can I manage to this shortly?
推荐答案
创建一个字典,将每个数字映射到一个字母,然后查找它们。将您的号码存储在一个列表中,这样您就可以拥有任意数量的按钮,而且您的代码仍然可以使用
Create a dictionary that maps each number to a letter, then look them up. Store your numbers in a list, so you can have any number of buttons you like and your code will still work
这篇关于如何将数字写为代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!