You are not logged in. Please login at www.codechef.com to post your questions!

×

Codeforces String Task Need Help

Can anyone tell me why my test case gives SIGSEV when input is femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM The problem is String Task Here is my implementation:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
    // your code goe
    string s1;
    string s2 = "";
    cin>>s1;
    int c = 0;
    int len = s1.length();
    for(int i=0;i<len;i++)
    {
        s2[i] = tolower(s1[i]);
        if(s2[i] == 'a' || s2[i] == 'e' || s2[i] == 'i' || s2[i] == 'o' || s2[i] == 'u' || s2[i] == 'y')
            continue;
        else
            cout<<'.'<<s2[i];
    }
    return 0;
}

asked 03 Apr '18, 22:37

montycs's gravatar image

0★montycs
1057
accept rate: 0%


The reason why your code is giving TLE is because you have a string named s2 that is empty and you want to assign s2[i] = (some character) where i belongs to [0,1,..,len-1]. This basically means you want to write at some memory location that your program doesn't have access to write. So what you need to do is instead of string s2 you can make a char variable and it will be fine or alternatively you can resize s2 to len by s2.resize(len); then also it will be fine.

link

answered 03 Apr '18, 23:11

mohit_yadav389's gravatar image

2★mohit_yadav389
903
accept rate: 25%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×672

question asked: 03 Apr '18, 22:37

question was seen: 150 times

last updated: 03 Apr '18, 23:11