D - Polycarp and Div 3

题目:

Polycarp likes numbers that are divisible by 3.

He has a huge number ss. Polycarp wants to cut from it the maximum number of numbers that are divisible by 33. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after mm such cuts, there will be m+1m+1 parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by 33.

For example, if the original number is s=3121s=3121, then Polycarp can cut it into three parts with two cuts: 3|1|213|1|21. As a result, he will get two numbers that are divisible by 33.

Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid.

What is the maximum number of numbers divisible by 33 that Polycarp can obtain?

Input

The first line of the input contains a positive integer ss. The number of digits of the number ss is between 11 and 2⋅1052⋅105, inclusive. The first (leftmost) digit is not equal to 0.

Output

Print the maximum number of numbers divisible by 33 that Polycarp can get by making vertical cuts in the given number ss.

Examples

Input

3121

Output

2

Input

6

Output

1

Input

1000000000000000000000000000000000

Output

33

Input

201920181

Output

4

Note

In the first example, an example set of optimal cuts on the number is 3|1|21.

In the second example, you do not need to make any cuts. The specified number 6forms one number that is divisible by 33.

In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and 3333 digits 0. Each of the 3333 digits 0 forms a number that is divisible by 33.

In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers00, 99, 201201 and 8181 are divisible by 33.

题意:

给你一个超级大的数,让你把这个数进行分割,然后尽量分隔出来能被3整除的数,让你求最多能够分割出来的数;

思路:

这道题算是有一个坑吧,最容易死在第11组数据上;

对于数据能够被3整除,那么这个数的每一位数相加也能够被3整除,

如果第一位数能够被3整除,那么这个数能够被3整除;

接下来考虑下一位数,

如果第二位数和第一位数的和能够被3整除,那么这个二位数也能够被3整除;否则考虑第3位数,

由第一二位数我们可以知道,第一位数的余数应该是0,1,2,第一二位数的余数应该是0,1,2;

当余数为0时,结果+1,所以不符合条件的余数组合就是(1,1,x)和(2,2,x);

关于第3位数的余数,我们可以发现无论第3位数的余数为几,结果都是可以被3整除的;

例如:

被第1位的余数和前两位的余数进行过判定后就剩下了这几种情况;

(1,1,1):3位和能被3整除;

(1,1,2):后两位和能被3整除;

(2,2,1):后两位和能被3整除;

(2,2,2):后三位和能被3整除;

也就是说,剩下的这几种情况都是可以被3整除的,就等于只要判断3位数,就有一种情况在我们的判断之外并且可以被3整除,所以代码中就有了k==3时,sum++;这一条;

for(i=0;i<l;i++)
{
    t=(a[i]-'0')%3;
    s+=a[i]-'0';
    k++;
    if(t==0||s%3==0||k==3)
    {
       sum++;
       k=0;
       s=0;
    }
 }

例如:

221;

那么我们可以知道,第1位,前2位和前3位  不可以被3整除,但是后两位可以分割出来被3整除,所以这就是我们容易忽略的地方;

代码如下:
 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

char a[200010];

int main()
{
    while(~scanf("%s",a))
    {
        int l=strlen(a);
        int i,t,s=0,sum=0,k=0;
        for(i=0;i<l;i++)
        {
            t=(a[i]-'0')%3;//判断第一位数;
            s+=a[i]-'0';//判断前两位数;
            k++;//记录是第几位数;
            if(t==0||s%3==0||k==3)//k==3,代表每判断3位数就会用一个肯定会被3整除的数字出现;
            {
                sum++;
                k=0;//还原;
                s=0;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值