-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1397.cpp
73 lines (73 loc) · 1.17 KB
/
1397.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
#include <iostream.h>
#include <string.h>
int code_len,n,time_n;
bool flag[100];
char start[10],code[100],end[10],temp_code[100];
void change(char *p)
{
if (*p<='Z'&&*p>='A')//A-Z
{
if (p!=code) {*p='?';time_n++;}
if (p+1<code+n) change(p+1);
//else change(code+n-1);
}
else
{
if (*p>'0')
{
*p=*p-1;time_n++;
if (p!=code+n-1)
{
if (p+*p-'0'+1>code+n-1)
{
if (p+1<code+n-1) p++;
else p=code+n-1;
}
else p+=*p-'0'+1;
change(p);
}
}
}
}
void changecontinue(int i)
{
char *p;
int count=0;
p=code+i+1;
for (;p<code+n;p++)
{
if (*p!=temp_code[p-code]) count++;
}
p=code+i;
*p=(count%10)+'0';
}
int main ()
{
int i;
while (cin>>start)
{
if (strcmp(start,"ENDOFINPUT")==0) break;
cin>>n;
memset(flag,0,sizeof(flag));
//cout<<start<<endl;
cin>>code; strcpy(temp_code,code);
cin>>end;
time_n=0;
//
if (code[0]!='0') change(code);
if (code[0]>='A'&&code[0]<='Z') code[0]=(char)(time_n%10+'0');//A-Z
for (i=0;i<n;i++)
{
if (code[i]<'A'||code[i]>'Z')
{
if (code[i]=='?')
{
changecontinue(i);
}
}
}
//cin.getline(end,10);
if (strcmp(end,"END")==0) cout<<code<<endl;
}
return 0;
}