-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpucmm025.cpp
136 lines (117 loc) · 3.18 KB
/
pucmm025.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include<bits/stdc++.h>
#define MAX 100000
#define DEBUG(x) do { std::cout << #x << ": " << x << std::endl; } while (0)
using namespace std;
int divisible(int num[],int len,int div){
int i,sum=0,ans=0;
switch(div){
case 0: ans= -1;
break;
case 1: ans= 1;
break;
case 2: if(num[len-1] %2 ==0)
ans= 1;
else
ans= -1;
break;
case 3: for(i=0;i<len;++i)
sum+= num[i];
if(sum%3==0)
ans= 1;
else
ans= -1;
break;
case 4: sum=0;
if(len==1)
{ if(num[len-1]%4==0)
ans= 1;
else ans= -1;
}
sum= num[len-2]*10 + num[len-1];
if(sum%4==0)
ans= 1;
else
ans= -1;
break;
case 5: if(num[len-1]==0 || num[len-1]==5)
ans= 1;
else
ans= -1;
break;
case 6: if(divisible(num,len,2)==1 && divisible(num,len,3)==1)
ans= 1;
else
ans= -1;
break;
case 7: i=0;
sum=num[i];
while(1){
sum= sum%7;
if(i+1 >=len)
break;
sum= sum*10 + num[++i];
}
if(sum==0)
ans= 1;
else
ans= -1;
break;
case 8: if(len==1)
{ if(num[len-1]%8==0)
ans= 1;
else
ans= -1;
}
else if(len==2)
{ sum= num[len-2]*10 + num[len-1];
if(sum%8==0)
ans= 1;
else
ans= -1;
}
else{
sum= num[len-3]*100+num[len-2]*10 + num[len-1];
if(sum%8==0)
ans= 1;
else
ans= -1;
}
break;
case 9: for(i=0;i<len;++i)
sum+= num[i];
if(sum%9==0)
ans= 1;
else
ans= -1;
}
return ans;
}
int main(){
int i,j,n,t,ans=0;
int dp[10]={0};// not checked
int len=0,num[240];
char ch;
char s[MAX];
cin>>s;
i=0;
len =strlen(s);
while(i<len){
num[i]=s[i] -'0';
++i;
}
for(i=0;i<len;++i)
{
//DEBUG(num[i]);
if( dp[num[i]]==1)
++ans;
else if(dp[num[i]]==0){
dp[num[i]]= divisible(num,len,num[i]);
if(dp[num[i]]==1)
++ans;
}
//DEBUG(dp[num[i]]);
//DEBUG(ans);
}
cout<<ans<<endl;
return 0;
}