zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    ASP.NET MVC 3: Razor中的@:和语法
    如何设置VS的代码智能提示
    七次
    不知不觉
    一切一切
    什么是喜欢
    Oracle的substr函数简单用法与substring区别
    前端必读:浏览器内部工作原理(转载)
    sublime text 插件安装 Mac版的
    一个随机上翻的小效果
  • 原文地址:https://www.cnblogs.com/lemon-jade/p/9386468.html
Copyright © 2011-2022 走看看