B. Spreadsheets

本文介绍了一种算法,用于在两种不同的表格坐标系统间进行转换。一种是常见的字母加数字表示法,如BC23;另一种是数值型表示法,如R23C55。通过解析输入坐标,算法能准确地在两者间进行转换,适用于处理大规模坐标数据的场景。

链接:https://codeforces.com/contest/1/problem/B

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.

Examples

input

Copy

2
R23C55
BC23

output

Copy

BC23
R23C55

题解:

#include <bits/stdc++.h>
using namespace std;
long long r,c,n;
char q[100];
int main()
{
	
	cin>>n;
	while(n--)
	{
		cin>>q;
		int i=0;
		if (sscanf(q,"R%dC%d", &r,&c)==2)
		{
			while (c)
			{
				c--;
				q[i++]=c%26+'A';
				c/=26;
			}
			for (i--;i>=0;i--)
				putchar(q[i]);
			printf("%d\n",r);
		}
		else
		{
			c=0;
			for (i=0;isalpha(q[i]);i++)
			{
				c*=26;
				c+=q[i]-'A'+1;
			}
			printf("R%sC%d\n",q+i,c);
		}
	}
}

 

这个错误表明在尝试访问Excel Range对象的`Type`属性时出现了问题。由于您使用的是WPS表格(从错误信息中的"Upgrade WPS Spreadsheets"可以看出),而非Microsoft Excel,部分属性和方法与标准Excel对象模型有所不同。以下是修正后的完整代码: ```python import os import shutil import win32com.client as win32 def copy_and_modify_excel(): # 输入文件路径 input_path = r"E:\桌面\sigif\input\Z1_N_J3_Cm251-003-009_Sigif_vo_ComCbk_ADC_13_B_Byte_8_UnitTestSpec.xlsm" output_dir = r"E:\桌面\sigif\output" if not os.path.exists(output_dir): os.makedirs(output_dir) excel = win32.gencache.EnsureDispatch('Excel.Application') # 或使用'Ket.Application'针对WPS excel.Visible = False excel.DisplayAlerts = False try: # 读取输入文件的J13值(WPS兼容方式) wb_input = excel.Workbooks.Open(input_path) sheet_name = "テーブル" initial_value = 72 # 默认值 try: if sheet_name in [sh.Name for sh in wb_input.Sheets]: target_cell = wb_input.Sheets(sheet_name).Range("J13") # WPS兼容的调试信息获取方式 print(f"Debug - 单元格值: {target_cell.Value}") print(f"Debug - 是否有公式: {'是' if target_cell.Formula else '否'}") initial_value = target_cell.Value if target_cell.Value is not None else 72 except Exception as e: print(f"⚠ 读取J13值时出错,使用默认值72: {e}") finally: wb_input.Close() print(f"使用的J13初始值为: {initial_value}") # 生成64个文件,编号从10到73(0010-0073) for i in range(10, 74): new_filename = ( os.path.basename(input_path) .replace("003-009", f"003-{i:04d}") .replace("Byte_8", f"Byte_{i-1}") ) output_path = os.path.join(output_dir, new_filename) try: shutil.copy2(input_path, output_path) wb = excel.Workbooks.Open(output_path) # 修改内容(优化后的安全替换) for sheet in wb.Sheets: used_range = sheet.UsedRange for row in range(1, used_range.Rows.Count + 1): for col in range(1, used_range.Columns.Count + 1): cell = used_range.Cells(row, col) try: if cell.Value and isinstance(cell.Value, str): new_value = cell.Value.replace("Byte_0", f"Byte_{i-1}").replace("Byte_8", f"Byte_{i-1}") if new_value != cell.Value: cell.Value = new_value except Exception as cell_error: print(f"单元格处理跳过: {cell_error}") # 设置J13值 try: if sheet_name in [sh.Name for sh in wb.Sheets]: new_value = initial_value + (i - 9) wb.Sheets(sheet_name).Range("J13").Value = new_value print(f"生成: {new_filename} | J13 = {new_value}") except Exception as e: print(f"❌ 设置J13出错: {e}") wb.Save() wb.Close() except Exception as file_error: print(f"❌ 文件处理失败: {file_error}") if 'wb' in locals() and wb: wb.Close() except Exception as main_error: print(f"❌ 主流程错误: {main_error}") finally: excel.Quit() del excel if __name__ == "__main__": copy_and_modify_excel() print("✅ 处理完成!") ``` ### 关键改进点: 1. **WPS兼容性处理**: - 移除了不兼容的`.Type`属性检查 - 使用更通用的`.Formula`和`.Value`属性 - 添加了更全面的异常捕获 2. **单元格处理优化**: - 仅在值确实改变时才执行写入操作 - 跳过非字符串和非变更内容提升性能 3. **调试增强**: - 显示实际使用的J13初始值 - 每个文件的生成状态实时输出 4. **资源管理**: - 确保工作簿正确关闭 - 添加了更完善的清理逻辑 ### 使用建议: 1. 如果J13值仍不正确,可以: ```python # 强制使用特定值(临时调试) initial_value = 72 # 替换读取逻辑 ``` 2. 如需验证所有Byte替换: ```python # 在替换后添加验证 print(f"示例替换: Byte_8 → Byte_{i-1}") ``` 3. 对于大批量文件处理: - 考虑添加进度显示 - 可分批次处理以避免内存问题
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值