-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
112 lines (111 loc) · 2.47 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//Incomplete
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
int t,n,i,r0,r1,r2,p,s;
string num;
cin>>t;
while(t--)
{
r0=0;
r1=0;
r2=0;
s=0;
p=0;
cin>>n;
cin>>num;
for(i=0;i<n;i++)
{
if(num[i]=='1' || num[i]=='4' || num[i]=='6' || num[i]=='8' || num[i]=='9')
{
p=1;
cout<<1<<"\n";
cout<<num[i]<<"\n";
break;
}
}
if(p==1)
continue;
for(i=1;i<n;i++)
{
if(num[i]=='2' || num[i]=='5')
{
p=1;
cout<<2<<"\n";
cout<<num[0]<<num[i]<<"\n";
break;
}
}
if(p==1)
continue;
for(i=0;i<n;i++)
{
int x=(num[i]-'0')%3;
if(x==0)
r0++;
else if(x==1)
r1++;
else
r2++;
}
if(r1>=1 && r2>=1)
{
cout<<2<<"\n";
for(i=0;i<n;i++)
{
if(p==1)
break;
if((num[i]-'0')%3==2)
{
cout<<num[i];
for(int j=i+1;j<n;j++)
{
if((num[j]-'0')%3==1)
{
cout<<num[j]<<"\n";
p=1;
break;
}
}
}
else if((num[i]-'0')%3==1)
{
cout<<num[i];
for(int j=i+1;j<n;j++)
{
if((num[j]-'0')%3==2)
{
cout<<num[j]<<"\n";
p=1;
break;
}
}
}
}
}
if(p==1)
continue;
if(r0>=2)
{
cout<<2<<"\n";
cout<<33<<"\n";
continue;
}
for(i=0;i<n;i++)
{
if(num[i]=='7')
s++;
}
if(s>=2)
{
cout<<2<<"\n";
cout<<77<<"\n";
continue;
}
}
return 0;
}