OddString(ABC072&ARC082)

Posted lemon-jade

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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("
");
    return 0;
}

 

以上是关于OddString(ABC072&ARC082)的主要内容,如果未能解决你的问题,请参考以下文章

072.火车车厢重排

Python入门100题 | 第072题

华为OJ072-火车进站

STM32 LoRaWAN探索板B-L072Z-LRWAN1中文用户手册

AtCoder Regular Contest 072 E:Alice in linear land

APM/STM32F072RB基于HAL库配置USB CDC虚拟串口功能