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;
        }
    }


}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章