CodeForces

来源:互联网 发布:epub360 知乎 编辑:程序博客网 时间:2024/06/06 01:28

第一次了解到sscanf函数,功能真是强大!另外,第一次提交时,在text 6 WR, 后于cf上查了检测数据后才知道忽略了一种情况,真是如同一位网友说的AC路漫漫啊。

这里先附上一位大牛写的博文:C语言函数sscanf()的用法


题目链接: CodeForces - 1B Spreadsheets

题目分析:其实题意比较简单,主要是要注意到当输入C26时应输出Z。


题目代码:

#include<cstdio>int r, c;char str[100], AZ[100];void exchange_1(){char az[100];int i, j;for(i=0; c>0; i++){az[i] = (c-1) % 26 + 'A'; // 考虑到当c=26时,应为Z。若是c%26+'A'-1,则得到的是‘A'-1。c = (c-1) / 26;}for(j=i-1; j>=0; j--){putchar(az[j]);}printf("%d\n", r);}/* 用递归void exchange_l(int c)   {  if(!c)   {  return;  }  exchange_l((c - 1)/26);  putchar(((c - 1)% 26) + 'A');  }  */  void exchange_2(){printf("R%dC", r);char *pt = NULL;int cc = 0;for(pt=AZ; *pt; pt++){cc *= 26;cc += *pt - 'A' +1;}printf("%d\n", cc);}int main(){int n;scanf("%d", &n);while(n--){scanf("%s", str);if(2 == sscanf(str, "R%dC%d", &r, &c)){exchange_1();}else{sscanf(str, "%[A-Z]%d", AZ, &r);exchange_2();}}return 0;}




0 0
原创粉丝点击