TOPIC

Wrong Answer (5%)

Bruno Machado Lobell asked 2 years ago

Eu não encontrei um caso de teste que não de certo. Nem nos casos base e nem no uDebug

#include <iostream>

int main() {
  char ent[100];
    std::cin.getline(ent,100);
    std::string s (ent);
    for(int i = 0; i < s.size(); i++)
        if(s[i] == ','){
            s[i] = '\n';
            break;
        }
    std::cout << s << std::endl;
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 years ago

    100 bytes + '\0'= 101 as minimum for a buffer. Buf why be so humble?

      char ent[128];
        std::cin.getline(ent,128);
        std::string s (ent);

    or better

        std::string s;
        std::getline(std::cin,s);

    Please, see https://ru.cppreference.com/w/cpp/string/basic_string/getline