在一行上输入一个仅由小写字母组成的字符串 ,长度为 。
在一行上输出一个字符串代表答案。
helloworld
helo
书写过程:第一行:h (取 1 个字母)第二行:el (取 2 个字母)第三行:low (取 3 个字母)第四行:orld (取 4 个字母)每行的首字母依次为:h、e、l、o 。
hello
hel
#include <bits/stdc++.h> using namespace std; signed main() { string s; cin >> s; int cnt = 1; string res = ""; for (int i = 0; i < s.size(); i += cnt ++ ) { res += s[i]; } cout << res << '\n'; return 0; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题