Codeforces综合训练

发布于 2019-10-22  107 次阅读


训练内容

Codeforces Beta Round #1

A

简单题,不写题解了

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

long long n,m,a,flaga,flagb;

int main(){
scanf("%I64d %I64d %I64d",&n,&m,&a);
if(n%a)flaga=1;
if(m%a)flagb=1;
printf("%I64d\n",(n/a+flaga)*(m/a+flagb));
return 0;
}

B

字符串处理,本质上是个进制转换,要注意一些细节

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;

const int N=100005;

int test;
char str[N];

int main(){
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
scanf("%d",&test);
while(test--){
    scanf("%s",str+1);
    int len=strlen(str+1),flag=1;
    for(register int i=2;i<=len;i++){
        if(str[i-1]>='0' && str[i-1]<='9' && str[i]>='A' && str[i]<='Z')flag++;
    }
    int row=0,col=0;
    if(flag==1){
        for(register int i=1;i<=len;i++){
            if('A'<=str[i] && str[i]<='Z')col=col*26+str[i]-'A'+1;
            if('0'<=str[i] && str[i]<='9')row=row*10+str[i]-'0';
        }
        printf("R%dC%d\n",row,col);
    }
    else {
        int fa=0;
        for(register int i=2;i<=len;i++){
            if(str[i]=='C')fa=1;
            else {
                if(fa)col=col*10+str[i]-'0';
                else row=row*10+str[i]-'0';
            }
        }
        stack<int> Stk;
        while(col){
            Stk.push((col-1)%26+1);
            col=(col-1)/26;
        }
        while(!Stk.empty()){putchar('A'-1+Stk.top());Stk.pop();}
        printf("%d\n",row);
    }
}
return 0;
}

C

It is my final heart.
最后更新于 2019-10-22