首页 > 其他分享 >Codeforces 1 B. Spreadsheets

Codeforces 1 B. Spreadsheets

时间:2022-12-05 18:33:51浏览次数:39  
标签:26 Console int Codeforces Spreadsheets Substring str indexNum

题意:

EXCEL 单元格位置表示方法相互转化  R23C55 <=> RC23

思路

AAA <=> 26 ^ 2 + 26 + 1

用到知识点:

正则表达式匹配

字符串反转

字符串出现位置

C# 10 .net6 代码

using System.Text;
using System.Text.RegularExpressions;

int n = int.Parse(Console.ReadLine()!);
while (n-- > 0)
{
    string str = Console.ReadLine()!;
    Regex regex = new Regex(@"^R\d+C\d+$");
    if (regex.IsMatch(str))
    {
        int indexC = str.IndexOf('C');
        int r = int.Parse(str.Substring(1, indexC - 1));
        int c = int.Parse(str.Substring(indexC + 1, str.Length - indexC - 1));
        StringBuilder sb = new StringBuilder();
        while (c > 0)
        {
            sb.Append((char)('A' + (c - 1) % 26));
            c -= (c - 1) % 26 + 1;
            c /= 26;
        }
        Console.WriteLine($"{new string(sb.ToString().ToCharArray().Reverse().ToArray())}{r}");
    }
    else
    {
        int indexNum = str.IndexOfAny("0123456789".ToCharArray());
        string cStr = str.Substring(0, indexNum);
        int c = 0;
        foreach (var item in cStr)
        {
            c *= 26;
            c += item - 'A' + 1;
        }
        Console.WriteLine($"R{str.Substring(indexNum, str.Length - indexNum)}C{c}");
    }
}

 

标签:26,Console,int,Codeforces,Spreadsheets,Substring,str,indexNum
From: https://www.cnblogs.com/luobo67/p/16953122.html

相关文章

  • Codeforces Global Round 1~3
    CF1110C回答\(q\)个关于\(a\)的询问,每次询问求:\(f(a)=max_{0<b<a}gcd(a\bigoplusb,a\&b)\),\(a<2^{25}\)假设\(a\)有\(k\)位,对\(a\)取个反,即\(b=\overlinea\)就......
  • Codeforces 1 A. Theatre Square
    题意:给定一块n*m大小的地方,用边长为a的石板全部覆盖。求最少需要多少石块覆盖。公式: (n+a-1)%a注意:数据范围用long运算先后关系,加括号C#10.net6代......
  • CodeForces 822F Madness
    CF传送门洛谷传送门*2500的黑(首先不考虑最小化字典序,我们发现\(res_i\ge\dfrac{2}{deg_u}\)。意思是理想的状态就是在一段周期内平均分配。这个下界是可以达到的,......
  • Codeforces Round #815 (Div. 2)
    比赛链接C题意:给定一个大小为n*m的01矩阵,每次操作你可以消除一个L形(\(2*2\)矩阵)内的所有1,每次必须保证消除至少一个1,求操作数的最大值。核心思路:这个其实我们需要模......
  • Educational Codeforces Round 132 (Rated for Div. 2)
    https://codeforces.com/contest/1709C.RecoveranRBS题意:这里原本有一个合法的括号序列,现在将这个合法的括号序列中的一部分字符串替换为?你可以将?替换为(或者)......
  • Codeforces Round #832 (Div. 2)
    A.TwoGroups(CF1747A)题目大意给定一个整数数组\(a\),要求将\(a\)分成两部分\(s1,s2\),要求两部分的和的绝对值的差最大。即最大化\(|\sum(s_1)|-|\sum(s_2)|\)......
  • Codeforces Round #816 (Div. 2)
    [比赛链接](Dashboard-CodeforcesRound#816(Div.2)-Codeforces)B题意:给定数组长度n,参数k,\(\sum_{1}^{n}a_i/k=b\),并且区间和是s。其中b和s都是题目给定的。核......
  • CodeForces - 476C-Dreamoon and Sums(数学思维)
    C.DreamoonandSums题解:设则有题目所求可得所以代码#include<bits/stdc++.h>typedeflonglongLL;usingnamespacestd;constintmod=1e9+7;intmain(){#ifndefO......
  • Codeforces Global Round 10 H. ZS Shuffles Cards
    题目链接设f[i]表示还有i个数不在集合内的期望步数,尝试列一下转移式,会发现式子由转移到下一轮的期望步数和之后的DP值组成,考虑DP的转移过程,就会发现答案为转移到下一轮的......
  • Codeforces Round #154(Div.2)
    C.TextEditor【题意】有一篇文章,包含\(i\)行,每行有\(a_i\)个字母,也就是\(a_i+1\)个放置光标的位置。对于一个位于\((x,y)\)光标,每次操作可以上移/下移/左移/......