【优化】Codeforces Beta Round #1 / 1B Spreadsheets (字符串处理)

codeforces-1B. Spreadsheets 1B. Spreadsheets 阅读详情

B. Spreadsheets
time limit per test
10 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

Input

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

Output

Write n lines, each line should contain a cell coordinates in the other numeration system.

Sample test(s)
input
2
R23C55
BC23
output
BC23
R23C55

比较下下面两个代码的不同之处~


完整代码:

/*186ms,0KB*/

#include<cstdio>
#include<cstring>
#include<cstdlib>

char str[17], col[8];

int main()
{
	int n, c, temp;
	bool hasc;
	scanf("%d", &n);
	while (n--)
	{
		memset(str, 0, sizeof(str));
		memset(col, 0, sizeof(col));
		scanf("%s", str);
		int len = strlen(str), i = 2, j = 0;
		hasc = false;
		for (; i < len; ++i) ///从2开始找'C'
		{
			if (str[i] == 'C')
			{
				if (str[i - 1] >= '0' && str[i - 1] <= '9')
					hasc = true;
				break;
			}
		}
		if (hasc) ///RXCY格式 转 字母+数字格式
		{
			///提取colnum
			for (j = i + 1; j < len; ++j)
				col[j - i - 1] = str[j];
			c = atoi(col);///#include<cstdlib>
			///10进制转26进制,最后逆序输出
			memset(col, 0, sizeof(col));
			j = 0;
			while (c > 26)
			{
				temp = c % 26;
				if (temp == 0)
					temp = 26;
				col[j++] = '@' + temp;
				c = (c - temp) / 26;
			}
			col[j] = '@' + c;
			for (; j >= 0; --j)
				printf("%c", col[j]);
			for (j = 1; j < i; ++j)
				printf("%c", str[j]);
		}
		else///字母+数字格式 转 RXCY格式
		{
			putchar('R');
			for (; str[j] > '@'; ++j)
				;
			temp = j - 1;
			for (; j < len; ++j)
				printf("%c", str[j]);
			putchar('C');
			c = 0;
			for (int index = 1; temp >= 0; --temp, index *= 26)
				c += (str[temp] - '@') * index;
			printf("%d", c);
		}
		printf("\n");
	}
	return 0;
}


更快的代码:

/*46ms,0KB*/

#include <cstdio>

char s[15], c;

int num(int b, int l)
{
	int temp = 0;
	for (int i = b; i < l; ++i)
		temp = temp * 10 + s[i] - '0';
	return temp;
}

int pow(int x, int y)
{
	int temp = 1;
	for (int i = 0; i < y; ++i)
		temp *= x;
	return temp;
}

int main()
{
	int n;
	scanf("%d\n", &n);
	while (n--)
	{
		int l = 0, f = 0;
		while ((c = getchar()) != '\n')
		{
			s[l++] = c;
			if (s[l - 2] >= '0' && s[l - 2] <= '9' && c > '9')
				f = l - 1;
		}
		if (f)
		{
			int temp = num(f + 1, l);
			l = f;
			while (temp > 0)
			{
				c = temp % 26 + '@';
				if (c == '@')
				{
					--temp;
					c = 'Z';
				}
				s[++l] = c;
				temp /= 26;
			}
			for (int i = l; i > f; --i)
				putchar(s[i]);
			for (int i = 1; i < f; ++i)
				putchar(s[i]);
			putchar('\n');
		}
		else
		{
			putchar('R');
			while (s[++f] > '9');
			for (int i = f; i < l; ++i)
				putchar(s[i]);
			int temp = 0;
			for (int i = 0; i < f; ++i)
				temp += (s[i] - '@') * pow(26, f - i - 1);
			printf("C%d", temp);
			putchar('\n');
		}
	}
	return 0;
}



自然语言处理(扩展学习1):Scheduled Sampling(计划采样)与Teacher forcing(教师强制) 作者:安静到无声作者简介:人工智能和硬件设计博士生、CSDN与阿里云开发者博客专家,多项比赛获奖者,发表SCI论文多篇。o( ̄▽ ̄)d。 阅读详情

相关推荐

生物信息学名词解释 | K-mer (长度为k的短序列)

K-mer 何谓K-mer 所谓Kmer,即为一段长度为k的DNA片段,是由测序reads剪切一部分得到的。k为一个奇数,k=几,就为几mer。 比如:我的测序reads长度为100bp,我将这100bp打断成17bp的短片段,打断后的17bp段片段就叫17mer,可以获得(100-17+1)条k-mer序列。 Table1 k-mers for GTAGAGCTGT. k k-mers 1 G,T,A,G,A,G,C,T,G,T 3 GTA,TAG,AGA,GAG,AGC,GCT,CT

qq_50637636的博客 2万+

Codeforces #1B Spreadsheet

一.问题描述:  In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is mar...

RTR 351

5.44GHz超高精度!STM32G474的HRTIM时钟配置避坑指南

本文深入解析STM32G474内置高分辨率定时器的时钟配置要点,帮助工程师避开常见陷阱。文章详细阐述了从系统时钟到5.44GHz等效时基的路径,重点分析了预分频器乘法器、周期计算溢出、影子寄存器同步等关键配置,并结合实测波形对比,确保HRTIM在电机控制、数字电源等精密应用中发挥极限性能。

book8的博客 529

B. Spreadsheets

time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the

无知的我 3004

MPU6050数据融合避坑指南:当欧拉角遇到万向节死锁,我们该如何处理?

本文深入探讨了MPU6050在姿态解算中遇到的欧拉角万向节死锁问题,提供了四元数解决方案及工程实践策略。通过分析死锁现象的本质,介绍四元数的优势与实现方法,并给出必须使用欧拉角时的三种应对方案,帮助开发者有效规避数据跳变和解算失效问题。

weixin_30415113的博客 546

UE4/5项目GPU崩溃?可能是Windows的TDR机制在搞鬼!深入浅出聊聊TdrDelay与显卡超时

本文深入探讨了UE4/5项目中GPU崩溃的常见原因,揭示了Windows TDR机制的工作原理及其对渲染进程的影响。通过调整TdrDelay参数和优化GPU负载,提供了解决显卡超时问题的实用方案,帮助开发者提升项目稳定性。

weixin_30691649的博客 415

行列转换

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number

hyesuixin的博客 500

MOOS-ivp 实验三 MOOS简介(1)

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 例如:第一章 Python 机器学习入门之pandas的使用 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录系列文章目录前言一、pandas是什么?二、使用步骤1.引入库2.读入数据总结 前言 提示:这里可以添加本文要记录的大概内容: 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 提示:以下是本篇文章正文内容,下面案例

weixin_44151170的博客 7440

Spreadsheet(翻译)

2022.1.18 题目网址: https://acs.jxnu.edu.cn/problem/CF1B 原题: Spreadsheet 10000ms65536K 描述: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, ...

qq_61768389的博客 352

21天教你学会PCIe专栏(14)--安全性考虑

1.1 定义安全性(Security):安全性是指保护系统免受未经授权的访问、攻击和破坏,确保数据的机密性、完整性和可用性。1.2 重要性数据保护:保护敏感数据,防止数据泄露和篡改。系统防护:防止恶意攻击,确保系统的稳定性和可靠性。合规性:满足行业标准和法律法规的要求,避免法律风险。用户信任:提高用户对系统的信任度,增强市场竞争力。通过今天的学习,你应该对PCIe安全性的重要性和常见威胁有了深入的了解,掌握了实施安全措施的方法和工具,以及安全开发的最佳实践。

xiaoheshang_123的博客 853

全网最全RT-DETR涨点改进,基于官方源码1:1还原,在Ultralytics项目中配置rtdetr-r18、rtdetr-r34、rtdetr-r50、rtdetr-r101版本~小论文大论文必备

本文详细介绍了如何将RT-DETR的ResNet18/34/50/101/154版本移植到ultralytics项目中。主要内容包括:1) RT-DETR核心特点,如高效混合编码器、IoU感知查询选择等;2) 提供完整ResNet核心代码;3) 分步配置指南,包括创建模块文件和修改tasks.py;4) 各版本yaml配置文件的创建方法。该方案可帮助研究者快速实现RT-DETR改进,适用于目标检测相关论文研究。所有配置文件均可正常运行,为实验部署提供了便利。

Ai缝合怪、助力小伙伴高效发论文 3991

Codeforces 1B. Spreadsheets

【题目来源】:点击打开链接【题目描述】:In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 t...

mcp3128 495

ROS2 - 乐动激光雷达 LD06

STL-06P 主要由激光测距核心,无线传电单元,无线通讯单元,角度测量单元、电机驱动单元和机械外壳组成。STL-06P 测距核心采用 DTOF 技术,可进行每秒 5000 次的测距。每次测距时,雷达发射出红外激光,激光遇到目标物体后被反射到单光子接收单元。

机器人控制与仿真应用 3504

Codeforces 1B.Spreadsheets

1 题目描述(题目链接) In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 2

qq_39378221的博客 346

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

训练-777-111

A - Spreadsheets CodeForces - 1B In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the seco...

weixin_30445169的博客 288

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

1B. Spreadsheets

B. Spreadsheets In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: colum

qq_39765898的博客 248

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

cf --1 --B

B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for ex

猿的进化 511

http://codeforces.com/contest/1/problem/B

B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following

sdjzqing的专栏 778

CodeForces 1B Spreadsheets(模拟)

B. Spreadsheets In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till colu

nudt_oys的博客 646

codeforces B. Spreadsheets 计算excel的行列

没想到这道题看起来这么简单,要写出无Bug的程序居然这么麻烦,要处理挺多情况的。 如: 1 判断是什么格式,然后转到相应的转换 2 26进制和10进制互相转换,如何处理 3 26进制还不是从0开始的,要如何处理 对应这里分了四个函数,应该都很清晰了。

靖空间 1718

Day 16 B. Spreadsheets

Problem: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 ha

Jackey_tao的博客 252

Spreadsheet

描述: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has nu

Liuxf的博客 252

B - Spreadsheet(进制转换+字符串大模拟)

B. Spreadsheets In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that ...

一只小蒟蒻的博客 790

Codeforces Beta Round #1-B. Spreadsheets

Codeforces Beta Round #1-B. Spreadsheets In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are

lunaol的博客 228

利用sprintf和sscanf实现十六进制和十进制之间的相互转换(转载)

( 在日常应用过程中,经常遇到二进制转换的问题,正好看到有这个非常简单的转换方法,记录下来,方便以后使用。) #include <stdio.h> int main() { char s[100] = {0}; sprintf(s, "%x", 15); printf("%s\n", s); // f char str[100] = "f"; int i = 0; sscanf(str, "%x", &i); printf("%d\n", i); // 15

博客 932

一个例子告诉你使用sscanf将十六进制字符串转换成二进制值

【代码】一个例子(带输出结果)告诉你使用sscanf将十六进制字符串转换成二进制值的方法。

847
上一篇: Codeforces Beta Round #98 (Div. 2) / 137A Postcards and photos (模拟)
下一篇: 编程中无穷大常量的设定技巧
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址