我需要制作一个代码,当您输入文本时,它会从您放置的句子中的每个单词的第一个字母开始。
例如,对于示例字符串"I like to play guitar and piano and drums"
,它应该打印"Iltpgapad"
答案 0 :(得分:5)
尝试这样的事情:
QGridLayout * lay = new QGridLayout();
lay->setAlignment(Qt::AlignLeft|Qt::AlignTop);
for (int i = 1; i < 15; ++i) {
QProgressBar * sl = new QProgressBar();
QSpacerItem * sp = new QSpacerItem(10, 10 + i);
lay->addWidget(sl, i, 0);
lay->addItem(sp, i, 0);
}
答案 1 :(得分:1)
此代码段与Python 3.x兼容:
print(''.join([x[0] for x in raw_input("Enter text:").split()]))
答案 2 :(得分:1)
line = "I like to play guitar and piano and drums"
letters = ""
words = line.split()
for word in words:
letters = letters + word[0]
print(" ".join(letters).upper())