Codeforces 1B Spreadsheet (模拟)(*1700)

http://codeforces.com/problemset/status

debug了好久的一份代码。思路简单就是模拟,昨天晚上写的时候脑子短路,写错一个地方然后就不好改了,错误的样例正好还是“IQ0”仿佛在嘲讽着什么hhh,以后可长点心⑧

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t --)
    {
        string s;
        cin>>s;
        int n = s.length();
        bool flag = 1;
        if(s[0] == 'R')
        {
            int j;
            for(j = 1; j < n; j ++)
            {
                if(s[j] >= 'A' && s[j] <= 'Z')
                    continue;
                else break;
            }
            for(int i = j; i < n; i ++)
            {
                if(s[i] >= '0' && s[i] <= '9')
                    continue;
                else
                {
                    flag = 0;
                    break;
                }
            }
        }
        if(! flag)
        {
            ll r = 0, c = 0;
            int i;
            for(i = 1; i < n; i ++)
            {
                if(s[i] >= '0' && s[i] <= '9')
                {
                    r = r * 10 + (int)(s[i] - '0');
                }
                else break;
            }
            for(int j = i + 1; j < n; j ++)
            {
                c = c * 10 + s[j] - '0';
            }
            int x[10005];
            int cnt2 = 0;
            while(c)
            {
                if(c % 26 != 0){
                    x[++ cnt2] = c % 26;
                    c /= 26;
                }
                else
                {
                    x[++ cnt2] = 26;
                    c -= 26;
                    c /= 26;
                }
                //c /= 26;
            }
            for(int i = cnt2; i >= 1; i --)
            {
                printf("%c",(char)(x[i]+'A'-1));
            }
            cout<<r<<endl;
        }
        else
        {
            cout<<'R';
            string ss = "";
            int now;
            for(int i = 0; i < n; i ++)
            {
                if(s[i] >= 'A' && s[i] <= 'Z')
                    ss += s[i];
                else
                {
                    now = i;
                    break;
                }
            }
            int len = ss.length();
            ll ans1 = 0;
            ll base = 1;
            for(int i = len - 1; i >= 0; i --)
            {
                ans1 += base * (int)(ss[i]-'A'+1);
                base *= 26;
            }
            for(int i = now; i < n; i ++)
                cout<<s[i];
            cout<<'C'<<ans1<<endl;
        }
    }
    return 0;
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值