随机字母 [英] Random Letters

查看:92
本文介绍了随机字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的简单问题。我试图弄清楚如何以这样的方式编写程序:当输入一个单词时,输出是该单词的每个单独字母的随机顺序。所以如果输入披萨,输出将是

P

Z

A



Z


我对如何输出字母有一个大概的想法,但不是没有它们重复。我喜欢自己解决这个问题,但我希望能指出正确的方向。继到目前为止代码:

Simple question here. Im trying to figureout how to write a program in such a way that when a word is entered, the output is each individual letter of that word in a random order. so if pizza is entered, the output would be
P
Z
A
I
Z

I have a general idea of how to output the letters, but not without them repeating. Id like to figure this out myself, but would appreciate being pointed in the right direction. heres the code thus far:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案

展开 | 选择 | Wrap | 行号



这里简单的问题。我试图弄清楚如何以这样的方式编写程序:当输入一个单词时,输出是该单词的每个单独字母的随机顺序。所以如果输入披萨,输出将是

P

Z

A



Z


我对如何输出字母有一个大概的想法,但不是没有它们重复。我喜欢自己解决这个问题,但我希望能指出正确的方向。继到目前为止代码:
Simple question here. Im trying to figureout how to write a program in such a way that when a word is entered, the output is each individual letter of that word in a random order. so if pizza is entered, the output would be
P
Z
A
I
Z

I have a general idea of how to output the letters, but not without them repeating. Id like to figure this out myself, but would appreciate being pointed in the right direction. heres the code thus far:
展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号



尝试使用0作为你的低限。当你有一个负的下限并且你的程序随机选择一个负数时,它将向后看你不需要做的单词。

另外,每次你找到一个随机的字母,将它从单词中删除,这样你就不会再次选择它。记得每次删除一个字母时都要减少一个字,因为这个字会更短

你甚至可以毫无界限地使用一个语句,如:
Try using 0 as your low bound. When you have a negative low bound and your program randomly picks a negative index, it will look backwards through the word which you don''t need to do.
Also, every time you find a random letter, remove it from the word so you don''t pick it again. Remember to decrease you high bound by one every time you remove a letter since the word will be shorter
You could even go without bounds at all and use a statement something like:
展开 | 选择 | Wrap | 行号


这篇关于随机字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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