Pagini recente » Cod sursa (job #2646854) | Cod sursa (job #2226695) | Cod sursa (job #1391751) | Cod sursa (job #1205177) | Cod sursa (job #732759)
Cod sursa(job #732759)
#include <fstream>
#include <cstdlib>
#include <ctime>
#define nmax 50005
using namespace std;
ifstream f("semne.in");
ofstream g("semne.out");
int n, cnt, a[nmax];
string rez;
int viz[nmax];
long long s, s2;
void citeste(){
f >> n >> s;
for(int i=0; i<n; i++) f >> a[i];
}
void rezolva(){
srand(time(NULL));
int ok = 1;
for(; ok; ){
int s2 = 0LL;
rez.clear();
for(int i=0; i<n; i++){
int x = rand()%2;
if (x == 0) s2 = s2+ (a[i]*1LL), rez+='+';
else s2=s2-(a[i]*1LL), rez+='-';
}
if (s2 == s){
g << rez << "\n";
ok = 0;
}
}
}
int main(){
citeste();
rezolva();
f.close();
g.close();
return 0;
}