Sentence Shifter
Здравейте! Опитвам се да подкарам задачата Sentence Shifter в judge, но ми дава следната грешка:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
Локално при мен (на VS 2019) работи. Сетнах стандарта на c++ 11, но продължава да работи при мен, но не и в judge. Ето кодът ми:
#include<iostream>
#include<queue>
#include<sstream>
void printCollection(const std::deque<std::string>& collection) {
for (const auto& word : collection) {
std::cout << word << std::endl;
}
}
void readInput(std::deque<std::string>& inputWords, size_t& inputShift) {
std::string line;
getline(std::cin, line);
std::istringstream istr(line);
std::string word;
while (istr >> word) {
inputWords.push_back(word);
}
std::cin >> inputShift;
std::cin.ignore();
}
class Shifter {
public:
Shifter(std::deque<std::string> words) {
_words = words;
}
void shiftWords(size_t shiftsCount) {
if (_words.empty()) {
return;
}
for (size_t i = 0; i < shiftsCount; ++i) {
const auto lastword = _words.back();
_words.pop_back();
_words.push_front(lastword);
}
}
std::deque<std::string> getShiftedSentence() {
return _words;
}
private:
std::deque<std::string> _words;
};
int main() {
std::deque<std::string> inputWords;
size_t inputShift;
readInput(inputWords, inputShift);
Shifter shifter = Shifter(inputWords);
shifter.shiftWords(inputShift);
const auto result = shifter.getShiftedSentence();
printCollection(result);
}
Мерси Живко! :)