B. Spreadsheets

链接: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);
		}
	}
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用ODBC连接来操作WPS的Excel文件需要进行以下几个步骤: 1. 安装WPS的ODBC驱动程序,这个驱动程序在WPS安装目录下的ODBC文件夹中,安装过程类似于安装其他软件,在安装过程中需要选择安装ODBC驱动程序。 2. 创建ODBC数据源: 打开“控制面板”->“管理工具”->“数据源(ODBC)”->“系统DSN”->“添加”,选择“WPS Spreadsheets ODBC”作为驱动程序,设置数据源名称和文件路径,完成创建。 3. 使用ODBC连接操作Excel文件: C++代码示例: ```c++ #include <iostream> #include <windows.h> #include <sql.h> #include <sqlext.h> using namespace std; int main() { SQLHENV hEnv; SQLHDBC hDbc; SQLHSTMT hStmt; SQLRETURN retcode; // 初始化环境句柄 retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Allocating Environment Handle" << endl; return -1; } // 设置ODBC版本为3.0 retcode = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Setting Environment Attribute" << endl; SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return -1; } // 初始化连接句柄 retcode = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Allocating Connection Handle" << endl; SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return -1; } // 连接Excel文件 retcode = SQLConnect(hDbc, (SQLCHAR*)"WPS Spreadsheets ODBC", SQL_NTS, NULL, 0, NULL, 0); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Connecting to WPS Spreadsheets ODBC" << endl; SQLFreeHandle(SQL_HANDLE_DBC, hDbc); SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return -1; } // 执行SQL语句 retcode = SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Allocating Statement Handle" << endl; SQLDisconnect(hDbc); SQLFreeHandle(SQL_HANDLE_DBC, hDbc); SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return -1; } retcode = SQLExecDirect(hStmt, (SQLCHAR*)"SELECT * FROM [Sheet1$]", SQL_NTS); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { cout << "Error Executing SQL Statement" << endl; SQLFreeHandle(SQL_HANDLE_STMT, hStmt); SQLDisconnect(hDbc); SQLFreeHandle(SQL_HANDLE_DBC, hDbc); SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return -1; } // 处理结果集 SQLCHAR col1[256], col2[256]; SQLLEN cbCol1, cbCol2; retcode = SQLBindCol(hStmt, 1, SQL_C_CHAR, col1, 256, &cbCol1); retcode = SQLBindCol(hStmt, 2, SQL_C_CHAR, col2, 256, &cbCol2); while (SQLFetch(hStmt) != SQL_NO_DATA) { cout << "Col1: " << col1 << ", Col2: " << col2 << endl; } // 释放句柄 SQLFreeHandle(SQL_HANDLE_STMT, hStmt); SQLDisconnect(hDbc); SQLFreeHandle(SQL_HANDLE_DBC, hDbc); SQLFreeHandle(SQL_HANDLE_ENV, hEnv); return 0; } ``` 该示例代码连接到WPS的Excel文件,并查询Sheet1工作表中的所有数据。需要注意的是,SQL语句中工作表名称需要用中括号括起来,并且以$符号结尾。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值