C language devil bumper ball

Title Description

Legend in the distant past, there is a big devil entrenched in ACM / ICPC lab.

Big devil is very powerful, and he's had four law enforcement B, CD and want to see the big devil, the Warriors must defeat eleven B, CD the four law enforcement.

That day, the Warriors led his new team-mates again attacked the laboratory. After they defeated the A law enforcement, they are being met distressed B Custodian.

After acetate law enforcement very surprised to see a pedestrian warrior. In fact, he is a person who loves sports, but since when on law enforcement, only one person alone keep in position.

B Custodian kind of hand holding the Warriors, the Warriors could take that as long as he played, and get a certain score, he directly put the Warriors in the past.

B Custodian of the left half of the pitch, Warriors standing in the right half of the center point. B 12345678 law enforcement turn the ball to eight points (as shown), after eight shots are to continue from the beginning.

1,7,3 known to the three-point ball 2 points, receiving the ball point 5,6 score 1, 4,8,2 received the ball point 3 points is obtained. If a second warrior did not get the ball, the Custodian will re-start from tee 1, continued to accumulate points.
Here Insert Picture Description

Entry

From the input line '0' and '1' s two-character string only (1 <= string length <= 106). Wherein when s [i] = '0' indicates not to warrior i-th ball law enforcement, s [i] == warriors represents the i-th ball received '1'.

Export

Output An integer representing the integral Warriors obtained.

Sample input Copy

11111111110111001

Sample output Copy

31

Code

#include<stdio.h>
#include<math.h>
#include<string.h>
int df(int a)
{int m;
	if(a%8==1||a%8==7||a%8==3)m=2;
	if(a%8==5||a%8==6)m=1;
	if(a%8==4||a%8==0||a%8==2)m=3;
	return m;
}
int main()
{
	char q[100000];
	int s=0, i=0,b,p=1;
	
	gets(q);

	for(i=0;i<strlen(q);i++)
	{
		if(q[i]=='1')
		{
			s=s+df(p);
			p++;
		}
		else p=1;

	}
	printf("%d\n",s);
	return 0;
}
Published 47 original articles · won praise 29 · views 1475

Guess you like

Origin blog.csdn.net/Qianzshuo/article/details/103759168