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



spreadsheet-api Formula One ActiveXspreadsheet-api-and-engine.pdf 立即下载

相关推荐

QT实现串口通信

要实现串口通信,需要知道串口通信需要的信息 主要参数有:波特率、校验位、数据位、停止位、控制流 主要操作有:串口的打开和关闭、刷新设备串口、接发数据、开关显示灯等。 实现效果如图: 最后附赠完整源码。 第一步:在头文件中引入 QtSerialPort 类的两个头文件(必须引入) // 引入串口通信的两个头文件(第一步) #include <QtSerialPort/QSerialPort> // 提供访问串口的功能 #include <QtSerialPo

m0_49456900的博客 6万+

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 349

用户消费行为分析(MapReduce实现,Hive分析)

一、题目要求 数据来自CDNow网站的一份用户购买CD明细,本数据集共有 6 万条 左右数据,数据为 CDNow 网站 1997年1月至1998年6月的用户行为 数据

紫烟的博客 3013

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

无知的我 3000

C#实战:5分钟搞定西门子S7-1200 PLC数据读写(S7netplus保姆级教程)

本文详细介绍了如何使用C#和S7netplus库快速实现与西门子S7-1200 PLC的数据读写。从环境准备、连接管理到数据读写高级技巧,提供了保姆级教程和实战方案,帮助开发者绕过常见陷阱,提升工业自动化项目的开发效率。

weixin_28432777的博客 283

SQLite学习——Dapper初识

dapper下载:https://www.nuget.org/packages/Dapper/1.40.0

jiDxiaohuo的博客 1296

行列转换

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的博客 498

手把手教你用AirSim生成无人机训练数据集:RGB/深度图/分割图全攻略

本文详细介绍了如何使用AirSim仿真插件在UE4环境中生成无人机训练数据集,涵盖RGB、深度图和分割图等多种模态数据的采集与处理。通过实战指南,读者可以掌握环境配置、多模态数据采集、自动化流程设计及数据后处理等关键技术,为无人机视觉算法开发提供高质量训练数据。

weixin_29008805的博客 449

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的博客 349

时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测

时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测 目录时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测基本介绍ARIMAXVARVARMAVARMAXSESHWES参考资料 基本介绍 本文介绍ARIMAX、VAR、VARMA和VARMAX基本概念及其Python程序设计。 ARIMAX 具有外源回归量的自回归整合移动平均值(ARIMAX)是 ARIMA 模型的扩展,其还包括外生变量的建模。 外生变量也称为协变量,可以被认为是并行输入序列,其在与

前程算法屋的博客 6688

tsmc12:via0的spacing问题(Via0.S.1)

12nm有个via0 grid的概念,除了普通fill外,基本都有via0这一层,这一层需要与via0 grid对齐。手动调整cell的位置比较容易出这个drc,比如修m0po max length drc时。解决方法1: 替换EEQV类型cell,这种类型是专门为了修via0 Grid问题存在的。更多学习内容请关注「拾陆楼」知识星球。解决方法2: 翻转或移动。

m0_61544122的博客 1115

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 493

【数据集7】全球人类住区层GHSL数据详解

全球人类住区层GHSL数据详解

WW、forever的博客 2253

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的博客 345

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

训练-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的博客 287

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

文章标题 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的博客 478

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

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

一只小蒟蒻的博客 787

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

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

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_的博客 302

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的博客 249

利用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将十六进制字符串转换成二进制值的方法。

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

余额充值