[2017百度之星程序设计大赛 - 复赛]A - hdu6144 B - hdu6145

这两道题都是属于模拟题,B题我弃坑了。

B题对于一个没有表达式的数,找出它的循环节。

对于一个表达式也是找出它展开后重复的部分,用快速幂和快速乘计算,首尾单独处理。

放一个A题

#include<cstdio>  
#include<algorithm>  
#include<cstring>  
#define fo(i,a,b) for(i=a;i<=b;i++)  
#define fd(i,a,b) for(i=a;i>=b;i--)  
using namespace std;  
const int N=1e5+5;  
const int P=1e9+7;  
int n,m;  
char s[N],s1[N],ch[N],s2[N];  
int main()  
{  
    int T;  
    register int i,j;  
    scanf("%d",&T);  
    while (T--)  
    {  
        scanf("%s",s);  
        int len=strlen(s),m=0,i=0;  
        while (i<=len-1)  
        {  
            if (s[i]=='(')  
            {  
                int cnt=0;  
                i++;  
                while (s[i]!=')')  
                {  
                    ch[++cnt]=s[i];  
                    i++;  
                }  
                i+=3;  
                int cnt1=0;  
                while (s[i]!=')')  
                {  
                    s2[++cnt1]=s[i];  
                    i++;  
                }  
                int tim=0,c=1;  
                fd(j,cnt1,1)tim=(tim+1ll*(s2[j]-'0')*c%P)%P,c=1ll*c*10%P;  
                while (tim--)  
                {  
                    fo(j,1,cnt)s1[++m]=ch[j];  
                }  
                i++;  
            }  
            else  
            {  
                s1[++m]=s[i];  
                i++;  
            }  
        }  
        int ans=0,c=1;  
        fd(i,m,1)  
        {  
            ans=(ans+1ll*(s1[i]-'0')*c%P)%P;  
            c=1ll*c*10%P;  
        }  
        printf("%d\n",ans);  
    }  
}  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值