Codeforces Round#339 div1,div2

A

这个题一点都不难,不过竟然会爆long long


代码如下

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;
int main(){
    LL l,r,k;
    while(~scanf("%lld%lld%lld",&l,&r,&k)){
        LL t=1;
        int flag=0;
        for(;t<=r;){
            if(t>=l&&t<=r&&t*k<=r){
                printf("%lld ",t);
                flag=1;
            }
            else if(t>=l&&t<=r&&t*k>r){flag=1;printf("%lld\n",t);}
            t=t*k;
            if(t%k!=0)break;//爆 long long 的处理

        }
        if(flag==0)printf("-1");
        printf("\n");
    }
}



B题

很简单,就是我做的时候很乱......

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 100000 + 40;
char str[maxn],ans[maxn];
int num,mark,m,flag;
void ori(){
    num=0;
    mark=0;
    m=0;
    flag=0;
}
int main(){
    int n;
    while(~scanf("%d",&n)){
            ori();
        for(int i=1;i<=n;i++){
            bool f=false;
            int cnt=0;
            m=0;
            cin>>str;
            int len=strlen(str);
            for(int j=0;j<len;j++){
                if(str[j]=='1')cnt++;
                else if(str[j]!='1'&&str[j]!='0'){m=1;break;}

            }
            if(m||cnt>1){flag=1;strcpy(ans,str);}
            else if(cnt)num+=len-1;
            else mark=1;
        }
        if(mark)cout<<"0"<<endl;
        else {
                if(flag)cout<<ans;
                else cout<<"1";
                for(int j=0;j<num;j++)cout<<"0";
                cout<<endl;
        }
    }


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值