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

来源:互联网 发布:淘宝卖家开通花呗设置 编辑:程序博客网 时间:2024/04/29 19:34

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

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

代码如下:

/* ***********************************************Author        :yinhuaCreated 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 longusing 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;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 pr界面字体太小怎么办 0p手机卡槽坏了怎么办 pr视频有水波纹怎么办 手机耳机插口插上没声音怎么办 xp系统电脑没有声音怎么办 win10笔记本耳机没声音怎么办 电脑插耳机还是外放怎么办 主机电脑耳机插孔坏了怎么办 苹果6plus有点卡怎么办 手机拨通电话后黑屏怎么办 手机拨通后没声音怎么办 苹果手机铃声不响了怎么办 婴儿喘气粗好像有痰怎么办 金毛呼吸声很大怎么办 回看福建导视该怎么办 楼上木地板走路声音都很响怎么办 班里团支不搭理我我该怎么办 客户买家具说贵怎么办 英雄联盟超出显示范围怎么办 脸上有斑点怎么办内条 脖子扭到了一动就疼怎么办 杭州限行在路上怎么办 在路上限行了怎么办 微信号不能进群怎么办 在微信约妹子被骗2000怎么办 qq号进不了热聊怎么办 网上买彩票中五百万怎么办 别人登我支付宝怎么办 医保刷卡刷到现金支付怎么办 微信诈骗立案后怎么办 奔跑吧诈骗填写了身份证怎么办 快手绑定的手机号丢了怎么办 球球大作战绑定手机号丢了怎么办 快手绑定手机号丢了怎么办 绑定银行卡的手机号丢了怎么办 爱奇艺绑定的手机号丢了怎么办 高铁票订错时间怎么办 微信音频视频打出没反应怎么办 海尔超低温保存箱低温报警怎么办 孕期吃了烧烤蔬菜怎么办 百姓动迁政府说话不算数怎么办