OddString(ABC072&ARC082)

题目描述

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

输入

The input is given from Standard Input in the following format:
s

输出

Print the string obtained by concatenating all the characters in the odd-numbered positions.

样例输入

atcoder

样例输出

acdr

提示

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;
}

 

posted @ 2018-07-29 19:14  jadelemon  阅读(446)  评论(0编辑  收藏  举报