题意:
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