# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
5502926 |
Contestant:
cgy4ever |
375A
- 37
|
GNU C++
|
Accepted
|
249 ms
|
2528 KB
|
2013-12-24 18:09:04 |
2013-12-24 20:07:27 |
|
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
string s;
int p1, p6, p8, p9;
bool check(string s)
{
int ret = 0;
for(int i = 0; i < s.length(); i++)
ret = (10 * ret + s[i] - '0') % 7;
return ret == 0;
}
int MAIN()
{
int start = clock();
cin >> s;
for(int i = 0; i < s.length(); i++)
if(s[i] == '1')
p1 = i;
else if(s[i] == '6')
p6 = i;
else if(s[i] == '8')
p8 = i;
else if(s[i] == '9')
p9 = i;
vector <int> ps;
ps.push_back(p1);
ps.push_back(p6);
ps.push_back(p8);
ps.push_back(p9);
while(!check(s))
{
if(clock() - start > 800) break;
if(rand()%3 == 0)
{
int a = rand()%4;
int b = rand()%4;
swap(s[ps[a]], s[ps[b]]);
}
else if(rand()%2 == 1)
{
int a = (rand() * 10000 + rand()) % s.length();
int b = (rand() * 10000 + rand()) % s.length();
swap(s[a], s[b]);
if(s[0] == '0')
swap(s[a], s[b]);
}
else
{
int a = rand()%4;
int b = (rand() * 10000 + rand()) % s.length();
swap(s[ps[a]], s[b]);
if(s[0] == '0')
swap(s[ps[a]], s[b]);
}
}
if(!check(s))
cout << 0 << endl;
else
cout << s << endl;
return 0;
}
int main()
{
#ifdef LOCAL_TEST
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios :: sync_with_stdio(false);
cout << fixed << setprecision(16);
return MAIN();
}
Click to see test details