You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
Constraints
Each character in s is a lowercase English letter.
1≤|s|≤105
Print the string obtained by concatenating all the characters in the odd-numbered positions.
Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.
题意:求奇数位置的字符
今天傻逼了。。。。。。。
写此博客以示警告
strlen()这个函数的时间复杂度是0(n),如果for(int i = 0; i < strlen(str); i++)这样操作,时间复杂度会是 0(n*n),但string 类型调用length()方法的时间复杂度是0(1)
AC code:
#include <bits/stdc++.h>
using namespace std;
const int N =1e6+10;
char str[N];
int main()
{
scanf("%s",str);
int krn=strlen(str);
for(int i = 0;i < krn;i++)
if(!(i&1))
printf("%c",str[i]);
printf("\n");
return 0;
}