【优化】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;
}



告别屏幕闪烁:手把手教你用示波器抓取并分析MIPI DSI信号(以RK平台为例) 本文详细介绍了如何利用示波器抓取并分析MIPI DSI信号,以解决LCD屏幕闪烁、花屏等问题。以RK平台为例,从工具准备、示波器参数配置到信号捕获与波形解读,提供了一套完整的调试方案,帮助硬件工程师快速定位和解决显示接口信号完整性问题。 阅读详情

相关推荐

安卓APP通过CH340实现USB串口通信与设备检测

本文详细介绍了安卓APP通过CH340芯片实现USB串口通信与设备检测的完整流程。从CH340芯片的基础原理到开发环境搭建,再到串口通信的具体实现和错误处理,提供了全面的技术指导。文章还分享了USB热插拔处理、自动重连策略以及性能优化等实战技巧,帮助开发者高效完成安卓与嵌入式设备的通信开发。

weixin_42531925的博客 387

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

IDEA系列(四):IDEA导入Maven工程项目并配置Tomcat启动

本片文章主要介绍如何导入一个存在的maven项目并配置Tomcat启动项目,方便自己使用,也分享出来,希望可以帮助到其他人。

低调D树苗的博客 1253

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

无知的我 3003

手把手教你用示波器抓取MIPI D-PHY波形:从LP11到HS Burst的完整信号解析

本文详细介绍了使用示波器精准捕获MIPI D-PHY信号的关键技巧,包括探头选择、示波器参数设置、信号状态解析及高级触发配置。通过实战案例和波形分析,帮助工程师快速识别从LP11到HS Burst的各种信号状态,解决常见的信号完整性问题,提升调试效率。

weixin_30471561的博客 570

LinuxCNC---在PC端显示开发板LinuxCNC界面

  今天在调试开发板时,执行开发板上的linuxcnc指令,总是出现如下报错 LINUXCNC - 2.9.0~pre0 application-specific initialization failed: couldn't connect to display "192.168.137.3:1" Error in startup script: invalid command name "image" while executing "image create photo -file $f/$i

中华田园巨龙 3478

行列转换

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

生产环境下oracle19c rac恢复节点2

现状:目前节点1数据库集群服务处于正常,节点2服务器由于系统故障无法恢复,确认系统重装。目标:不影响业务的情况下,重新把节点2添加回集群中。

sqlora的专栏 885

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

别再手动算了!用Excel函数一键搞定AQI和首要污染物分析(附完整公式模板)

本文介绍如何利用Excel函数自动化计算AQI和首要污染物分析,大幅提升数据处理效率。通过构建标准化输入模板、智能计算IAQI、自动判定AQI与首要污染物,并生成可视化仪表盘,帮助环保工作者快速完成每日监测报告。

weixin_30443075的博客 349

硕士论文排版救星:用Mathtype一键搞定所有公式格式(附样式预设文件)

本文详细介绍了如何使用Mathtype的样式预设和批量格式化功能,快速统一硕士论文中的公式格式。通过创建标准样式预设文件和一键批量处理,解决公式字体、大小、间距不统一的问题,确保符合学术规范要求,大幅提升论文排版效率。

weixin_30772105的博客 952

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

构建具有预测维护能力的AI Agent

随着工业4.0的推进,工业设备的复杂性和自动化程度不断提高,设备的稳定运行对于企业的生产效率和经济效益至关重要。预测维护作为一种先进的设备维护策略,能够通过对设备状态的实时监测和分析,提前预测设备故障,从而避免设备意外停机,降低维护成本。本文的目的是详细阐述如何构建具有预测维护能力的AI Agent,涵盖从数据采集、处理、模型训练到实际应用的整个流程,为企业和开发者提供全面的技术指导。本文将按照以下结构进行组织:首先介绍核心概念与联系,包括预测维护和AI Agent的基本原理和架构;

2501_92132293的博客 947

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

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

训练-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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

B. Spreadsheets题解

题目链接:http://codeforces.com/problemset/problem/1/B ①题意描述 ②代码实现 ③注意点和思路 ①题意描述:有两种表格位置的描述方式,第一种是RXCY的形式,其中X和Y是正整数,分别代表行标和列标;第二种用字母加数字的形式,字母代表列表数字行标(和excle规则一样)。 第一行输入一个数n,代表n组询问。然后接下来n行每行输入以上两种形式的其...

madama的博客 694

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

文章标题 CoderForces 1B : Spreadsheets(模拟)

SpreadsheetsDescription 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

Wang_SF2015的博客 479

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

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

Spreadsheets

Spreadsheets-codeforces 1BSpreadsheets

广告位出租~ 683

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

1.18 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

Zhouwen_的博客 306

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. ...

aaHua_ 472
上一篇: 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、付费专栏及课程。

余额充值