1095. Nikifor 3
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
2 1234 531234 |
4123 354123 |
Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session
All submissions (6843) All accepted submissions (2236) Solutions rating (1835)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int ssss[7]={4123,1324,1234,2341,1243,3421,3142};
char str[22];
int num[10];
int length;
int map[20];
int sum,flag,t;
long long int frontpart,pppp;
int main()
{
scanf("%d",&t);
while(t --)
{
memset(str,0,sizeof(str));
memset(map,0,sizeof(map));
memset(num,0,sizeof(num));
scanf("%s",str);length = strlen(str);
for(int i = 0;i < length;i ++)
num[str[i] - 48] ++;
num[1] --;num[2] --;num[3] --;num[4] --;
frontpart = 0;
pppp = 1;
int k = 1;
for(int i = 1;i <= 9;i ++)
{
while(num[i] >= 1)
{
frontpart = frontpart * 10 + i;
map[k ++] = i;
num[i] --;
}
}
k --;
//printf("%lld
",frontpart);
frontpart %= 7;
int i;
for(i = 0;i < 7;i ++)
{
if((frontpart * 10000 + ssss[i]) % 7 == 0)
break;
}
for(int l = 1;l <= k;l ++)
printf("%d",map[l]);
printf("%d",ssss[i]);
while(num[0] >= 1){
printf("0");num[0] --;}
printf("
");
}
return 0;
}