Witam,
Rozwiązuję zadanko ze spoja: http://pl.spoj.com/problems/TABLICA/
Dowaliłem rozwiązanie uwzględniające wszelkie możliwe kombinacje wpisania spacji, ma ktos pomysł co tu może być njie tak? Sędzia zwraca błędna odpowiedź.
Pozdrawiam.
#include <iostream> #include <cstdlib> #include <cctype> using namespace std; string arrayCleaner(string num){ string temp; for(int i = 0; i < num.length(); i++){ if((num[i] == ' ') && (num[i+1] == ' ')){ temp += ""; } else temp += num[i]; } if(temp[0] == ' ') temp.erase(0,1); for(int i = temp.length() - 1; i >= 0; i--){ if(isdigit(temp[i])){ break; } else temp.erase(i,1); } return temp; } int arrayLength(string num) { int counter = 1; for (int i = 0; i < num.length(); i++) { if (num[i] == ' ') { counter++; } } return counter; } int * arrayMaker(string num) { string temp = ""; int j = 0; int counter = arrayLength(num); int * array = new int [counter]; for (int i = 0; i < num.length(); i++) { if (num[i] != ' ') { temp += num[i]; if (i == (num.length() - 1)) { array[j] = atoi(temp.c_str()); } } if (num[i] == ' ') { array[j] = atoi(temp.c_str()); j++; temp = ""; } } return array; } void deleteArray(int * tab) { delete [] tab; } int main() { string number, str=""; int * t; while (getline(cin, str)) { number = arrayCleaner(str); t = arrayMaker(number); for (int i = 0; i < arrayLength(number); i++) { cout << t[arrayLength(number)-1-i]; if(i != (arrayLength(number)-1)) cout << ""; } cout << endl; deleteArray(t); } return 0; }