1B. Spreadsheets(字符串+数学)

本文探讨了如何在两种模式间进行字符串转换,并解决了模式识别过程中出现的问题,通过实例展示了模式转换的过程及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

脑残题。。。。(两种模式字符串互相转换)

还送了几发WA,原因是判断当前字符串是第一种模式还是第二种模式时出错了

代码如下:

/* ***********************************************
Author        :yinhua
Created Time  :2014年12月12日 星期五 14时06分37秒
File Name     :1B.cpp
************************************************ */

#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define LL long long
using namespace std;

int tmp[MAXN];
char str[10000];

int main() {
    char ch1, ch2;
    int T, i, row, col;
    scanf("%d", &T);
    while(T--) {
        memset(str, 0, sizeof(str));
        scanf("%s", str);
        int len = strlen(str);
        bool ok = false;
        for(i=0; i<len; ++i) {
            if(str[i]>='0'&&str[i]<='9') {
                ok = true;
                continue;
            }
            if(ok && str[i]>='A'&&str[i]<='Z') 
                break;
        }
        //printf("i = %d\n", i);
        if(str[0] == 'R' && i!=len) {

            sscanf(str, "%c%d%c%d", &ch1, &row, &ch2, &col);
            //printf("ch1 = %c\tch2 = %c\n", ch1, ch2);
            //printf("%d %d\n", row, col);
            int cnt = 0;
            while(col) {
                if(col%26 == 0) {
                    tmp[cnt++] = 26;
                    col = col/26-1;
                } else {
                    tmp[cnt++] = col%26;
                    col = col/26;
                }
            }
            for(int i=cnt-1; i>=0; --i) {
                printf("%c", 'A'+tmp[i]-1);
            }
            printf("%d\n", row);

        } else {
            row = col = 0;
            for(int i=0; i<len; ++i) {
                if(str[i]>='A' && str[i]<='Z') {
                    col = col*26+(str[i]-'A'+1);
                }
                if(str[i]>='0' && str[i]<='9') {
                    row = row*10+(str[i]-'0');
                }
            }
            printf("R%dC%d\n", row, col);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值