码迷,mamicode.com
首页 > 其他好文 > 详细

OddString(ABC072&ARC082)

时间:2018-07-29 20:01:28      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:assigned   rac   i++   input   类型   each   ace   复杂   osi   

题目描述

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

 

OddString(ABC072&ARC082)

标签:assigned   rac   i++   input   类型   each   ace   复杂   osi   

原文地址:https://www.cnblogs.com/lemon-jade/p/9386468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!