|
|
back to boardCan't understand, what's wrong. C++ I got WA 1, but when I test this code myself, I always get a correct answer. What's wrong? #include <iostream> using namespace std; int main() { char speech[1001]; cin.getline(speech, 1001); int cost = 0; for (int i = 0; i < 1001; i++) { switch (speech[i]) { case 'a': case 'd': case 'g': case 'j': case 'm': case 'p': case 's': case 'v': case 'y': case '.': case ' ': cost += 1; break; case 'b': case 'e': case 'h': case 'k': case 'n': case 'q': case 't': case 'w': case 'z': case ',': cost += 2; break; case 'c': case 'f': case 'i': case 'l': case 'o': case 'r': case 'u': case 'x': case '!': cost += 3; break;
} } cout << cost << endl;
return 0; } Edited by author 29.08.2018 19:40 Re: Can't understand, what's wrong. C++ Posted by PO 26 Jan 2019 11:44 why are you iterating to 1001 all the time? maybe to string length? though looks fine with case, but nevertheless worth trying |
|
|