Poštovani,
Radio sam zadatak sa državnog takmičenja za srednje škole 2016, konkretno B1 Maje. Ne mogun da pronadjem grešku u kodu, a tester mi izbacuje runtime error i wrong answer. Da li možete da mi pomognete oko zadatka, u nastavku teksta prilažem kod:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int sastavi(vector a){
int s = 0;
for (auto& i : a){
s += i;
s *= 10;
}
s /= 10;
return s;
}
vector rastavi(int s){
vector a;
while(s){
a.push_back(s % 10);
s /= 10;
}
reverse(a.begin(), a.end());
return a;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
a[0] = 0;
for (auto i = 1; i <= n; ++i){
cin >> a[i];
int minimax = INT32_MAX;
auto broj = rastavi(a[i]);
for (auto j = 0; j < 10; ++j){
auto tmp = sastavi(broj);
if (tmp < minimax && tmp >= a[i - 1])
minimax = tmp;
rotate(broj.begin(), broj.begin() + 1, broj.end());
}
if (minimax == INT32_MAX){
cout << "NE";
return 0;
}
a[i] = minimax;
}
cout << "DA";
}