0

I just start out on CodeForces. And I just encounter a problem, the code run on CodeForces compiler but not on my Codeblock (20.03 GCC version 8.1.0). I use windows 10. This problem on CodeForces: The problem.

  • this is the solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<char> c;
    char s;
    while(cin>>s)c.insert(s);
    cout<<(c.size()%2?"IGNORE HIM!":"CHAT WITH HER!");
}
  • When executing the provided code, I encountered an issue where it does not display the expected output as mentioned in the test case. Instead, when I copy the input from the test case and paste it into the console, the program keeps prompting for additional input without producing the desired output. It seems to be stuck in an infinite input loop.

  • I suspect that there might be an underlying problem with either the CodeBlocks program or the input provided by Codeforces when submitting the code.

  • So what is the problem? Thanks

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 1
    Whoever taught you to use `#include` led you horribly wrong: https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h?r=Saves_AllUserSaves – πάντα ῥεῖ May 19 '23 at 09:43
  • Codeforces is not a good place to learn C++. Good sources to learn cpp from are : A [recent C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or have a go at https://www.learncpp.com/ (that's pretty decent, and pretty up-to-date). For C++ reference material use : [cppreference](https://en.cppreference.com/w/). And after you learned the C++ basics from those sources, look at the [C++ coreguidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) regularely to keep up-to-date with the latest guidelines. – Pepijn Kramer May 19 '23 at 09:44
  • Even using `using namespace std;` is not recommended. use `#include ` instead of bits/stdc++.h – Pepijn Kramer May 19 '23 at 09:46
  • Your code reads to end of file. So your code reads beyond single line. Now in console you have to indicate end of file somehow. CodeForces redirects file to standard input so stream has natural end. – Marek R May 19 '23 at 09:52
  • @MarekR Oh, okay. You open up a few stuff I have never heard about. Thanks you – BuiHieuMinh May 19 '23 at 11:25

0 Answers0