-
Notifications
You must be signed in to change notification settings - Fork 6
/
ANARC05H.cpp
43 lines (41 loc) · 942 Bytes
/
ANARC05H.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
#include<iostream>
#include<string.h>
using namespace std;
int count;
int f(int val[25][25],char a[26],int pos,int presum)
{
for(int i=pos+1;i<strlen(a);i++)
{
if(val[pos][i-1]<=val[i][strlen(a)-1] && val[pos][i-1]>=presum)
{
//cout<<pos<<"-"<<i-1<<" , "<<i<<"-"<<strlen(a)-1<<"\n";
count++;
f(val,a,i,val[pos][i-1]);
}
}
}
int main()
{
char a[26];
int val[25][25]={ {-1 } },t=1;
while(1)
{
count=1;
cin>>a;
if(strcmp(a,"bye")==0)
break;
else
{
for(int i=0;a[i]!='\0';i++)
{
val[i][i]=a[i]-48;
if(i!=0)
val[0][i]=val[0][i-1]+val[i][i];
for(int j=1;j<i;j++)
val[j][i]=val[j][i-1]+val[i][i];
}
f(val,a,0,-1);
}
cout<<t++<<". "<<count<<"\n";
}
}