当前位置: 首页 > news >正文

B. Spreadsheets

Problem - B - Codeforces

问题描述:excel有两种情况,

  • Rr_nCc_nR行数C列数
  • ZZZ(列数)行数

对这两个进行相互转换。

细节:

  • 准确判断这两种情况
string str; cin>>str;
auto posR = str.find("R"), posC = str.find("C");
bool fg = false;
if(isdigit(str[posR+1])) fg = true;
if(fg && posR != -1 && posC != -1 && posR < posC) {// 第一种情况
} else {// 第二种情况
}
  • 十进制到26进制(带字母):注意 ‘A’,‘Z’。
col += ( (cv % 26 == 0 ? 25 : cv % 26 - 1) + 'A');
if(cv % 26 == 0) cv--;
cv /= 26;

AC代码:

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <random>
#include <sstream>
#include <numeric>
#include <stdio.h>
#include <functional>
#include <bitset>
#include <algorithm>
using namespace std;// #define Multiple_groups_of_examples
#define IOS std::cout.tie(0);std::cin.tie(0)->sync_with_stdio(false);
#define dbgnb(a) std::cout << #a << " = " << a << '\n';
#define dbgtt cout<<" !!!test!!! "<<endl;
#define rep(i,x,n) for(int i = x; i <= n; i++)#define all(x) (x).begin(),(x).end()
#define pb push_back
#define vf first
#define vs secondtypedef long long LL;
typedef pair<int,int> PII;const int INF = 0x3f3f3f3f;
const int N = 2e5 + 21;void inpfile();
void solve() {int n; cin>>n;while(n--) {string str; cin>>str;auto posR = str.find("R"), posC = str.find("C");bool fg = false;if(isdigit(str[posR+1])) fg = true;if(fg && posR != -1 && posC != -1 && posR < posC) {// R ... C ...int rv = 0, cv = 0;posR++;while(isdigit(str[posR])) {rv = rv * 10 + str[posR] - '0';posR++;}posR++;while(isdigit(str[posR])) {cv = cv * 10 + str[posR] - '0';posR++;}string col = "";while(cv) {col += ( (cv % 26 == 0 ? 25 : cv % 26 - 1) + 'A');if(cv % 26 == 0) cv--;cv /= 26;}reverse(all(col));cout<<col; cout<<rv<<endl;}  else {int pos = 0;while(isalpha(str[pos])) {pos++;}int rv = 0;string s = "";for(int i = 0; i < pos; ++i) {s += str[i];}int cv = 0;for(int i = 0; i < pos; ++i) {cv = cv * 26 + (s[i] - 'A' + 1);}while(isdigit(str[pos])) {rv = rv * 10 + str[pos] - '0';pos++;}cout<<'R'<<rv<<'C'<<cv<<endl;}}
}
int main()
{#ifdef Multiple_groups_of_examplesint T; cin>>T;while(T--)#endifsolve();return 0;
}
void inpfile() {#define mytest#ifdef mytestfreopen("ANSWER.txt", "w",stdout);#endif
}
http://www.lryc.cn/news/136009.html

相关文章:

  • matlab面向对象
  • 01、Cannot resolve MVC View ‘xxxxx前端页面‘
  • 时空智友企业流程化管控系统文件上传漏洞复现
  • 【已解决】Authenticator:无法添加账户请验证激活代码是否正确以及您的设备是否已为此应用启用推送通知
  • 聊聊springboot tomcat的maxHttpFormPostSize
  • java并发:synchronized锁详解
  • Unity 之NavMeshAgent 组件(导航和路径寻找的组件)
  • 装箱和拆箱
  • 等保测评--安全通信网络--测评方法
  • 统计学补充概念11-tsne
  • Linux_11_系统启动和内核管理
  • 【从零学习python 】65. Python正则表达式修饰符及其应用详解
  • QA2
  • centos7卸载docker
  • 【计算机视觉】递归神经网络在图像超分的应用Deep Recursive Residual Network for Image Super Resolution
  • Centos 7 安装系列(8):openGauss 3.0.0
  • NOIP真题讲解 传球游戏 接水问题
  • 《论文阅读18》 SSD: Single Shot MultiBox Detector
  • NOIP2016普及组第四题 魔法阵
  • uniapp-滑块验证组件wo-slider
  • NPM 管理组织成员
  • 设计模式(3)抽象工厂模式
  • 【C++】早绑定、析构与多态 | 一道关于多态的选择题记录
  • mac下安装tomcat
  • 【小梦C嘎嘎——启航篇】string常用接口的模拟实现
  • 【Jenkins】持续集成部署学习
  • Redis数据结构之List
  • SpringCloud Alibaba实战和源码(7)Skywalking
  • MySQL索引可能失效之or、is null、is not null、不等于(!=,<>)、联合索引
  • 无人机电力巡检:探索电力设施维护的新模式