SabooP's blog

By SabooP, history, 4 years ago, In English

Link to my code: https://codeforces.me/contest/1335/submission/86206704

O/P on other IDE's 254873296 386492714 729641735 853725149 975324628 412968347 632457982 598235471 247189562

But on codeforces I am getting two weird outputs.In one O/P I am getting just blank spaces while in other O/P I am getting correct output but with no line break; (published)

  • Vote: I like it
  • +9
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Since you are using char arrays as strings, you need to make sure that these strings end with a '\0' byte. Or better use c++ string class instead, it is usually less error prone.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    By using String class and getline the whole input of the test case is not accepted,i.e,Out of the 9 lines of sequences the code is not reading the last line..Now I am confused.I have also tried by cin, char array including null character at the end but I am not getting expected output. Here I am attaching the link of the same. https://codeforces.me/contest/1335/submission/86218770

    Please tell me where I am doing wrong!!

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      string s1; This creates a string object of length 0. If you want a specific length then just put arguments to the constructor: string s1(10, ' '); creates a string of ten blanks.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Ohk!!

        THen formally if I say like by declaring a string like this and taking input of length upto 1000 characters many of my previous codes were accepted . Can you explain the logic which poses problem here.Like to the point I want to get to know why by not declaring the string size poses a problem. Like in many cases it is possible that string size is not known to us beforehand. Then what to do in those situations.??

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          string s; cin>>s; works fine, no problem.

          string s; s[1]='a'; makes problems, because it is an access to undefined memory, an array out of bounds access.

          This is basic c++ knowledge. Try some of these tutorials.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +3 Vote: I do not like it

            Ohk Thanks a lot gentleman!!

»
4 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Dont mix cin/cout with scanf/printf if you use this ios_base::sync_with_stdio(0) and increase the size of the char arrays by 1 to accomodate the \0.