Pagini recente » Cod sursa (job #723190) | Cod sursa (job #100636) | Cod sursa (job #2444559) | Cod sursa (job #2890047) | Cod sursa (job #1950530)
#include <cstdlib>
#include <fstream>
#include <vector>
#include <ctime>
using namespace std;
ifstream f ("semne.in");
ofstream g ("semne.out");
const int Dim = 1e5;
vector <int> pls, mns;
int n, x, S, sum;
char ans[ Dim ];
int main() {
srand (time (NULL));
f >> n >> S;
for (int i = 1; i <= n; ++i) {
f >> x;
int sgn = rand () % 2;
if (sgn == 1) {
pls.push_back (x);
sum += x;
}
else {
mns.push_back (x);
sum -= x;
}
}
while (sum != S) {
if (sum < S) {
int pos = rand () % mns.size();
sum += 2 * mns[pos];
pls.push_back (mns[pos]);
swap (mns[pos], mns[mns.size() - 1]);
mns.pop_back();
}
else {
int pos = rand () % pls.size();
sum -= 2 * pls[pos];
mns.push_back (pls[pos]);
swap (pls[pos], pls[pls.size() - 1]);
pls.pop_back();
}
}
for (int i = 1; i <= n; ++i)
ans[i] = '-';
for (vector <int> :: iterator it = pls.begin(); it != pls.end(); ++it) {
ans[*it] = '+';
}
for (int i = 1; i <= n; ++i) {
g << ans[i];
}
return 0;
}