-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
47 lines (44 loc) · 886 Bytes
/
D.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
//BABE
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char a[100];
char adown[100];
char aup[100];
int numban;
char ban[9];
cin>>a;
strcpy(aup,a);
strcpy(adown,a);
cin>>numban;
int lena=strlen(a);
for (int i=0; i<numban; i++)cin>>ban[i];
for (int i=0; i<lena; i++)
{
for (int j=0; j<numban; j++)
{
if(adown[i] == ban[j])
{
adown[i]-=1;
if(i+1<lena)adown[i+1]='9';
}
}
}
for (int i=0; i<lena; i++)
{
for (int j=0; j<numban; j++)
{
if(aup[i] == ban[j])
{
aup[i]+=1;
if(i+1<lena)aup[i+1]='0';
}
}
}
if(adown[0]=='0')cout<<"impossible"<<endl;
else cout<<adown<<endl;
cout<<aup;
}