codeforces_1B Spreadsheets
2013-04-23 22:37
302 查看
题目链接 http://www.codeforces.com/problemset/problem/1/B
题目大意:两种表示法之间的转换。第一种:字母部分(列)+数字部分(行);第二种:R+行+C+列。
题目大意:两种表示法之间的转换。第一种:字母部分(列)+数字部分(行);第二种:R+行+C+列。
//C++代码 #include<iostream> #include<string> #include<cctype> using namespace std; int main(){ int n; cin>>n; while(n--){ string s; cin>>s; int len=s.size(),i=0,j,x,y; while(isalpha(s[i])) i++; while(isdigit(s[i]) && i<len) i++; if(i==len){ x=y=j=0; while(isalpha(s[j])) y=26*y+(s[j++]-'A'+1); while(j<len) x=10*x+(s[j++]-'0'); cout<<"R"<<x<<"C"<<y<<endl; } else{ x=y=0,j=1; while(isdigit(s[j])) x=10*x+(s[j++]-'0'); j++; while(j<len) y=10*y+(s[j++]-'0'); char ch[10]; j=0; while(y>0){ int z=y%26; if(z==0){ ch[j]='Z'; y-=26; } else ch[j]=char(z+64); y/=26; j++; } for(i=j-1;i>=0;i--) cout<<ch[i]; cout<<x<<endl; } } return 0; }
#python2.7 n=input() S=map(raw_input,['']*n) for s in S: ans='' if s[0]=='R' and s[1].isdigit() and 'C' in s: i=s.index('C') m=int(s[i+1:]) while m: ans=chr(ord('A')+(m-1)%26)+ans m=(m-1)/26 ans+=s[1:i] else: i=m=0 while s[i].isupper(): m=m*26+(ord(s[i])-ord('A')+1) i+=1 ans='R'+s[i:]+'C'+str(m) print ans
相关文章推荐
- codeforces 1B Spreadsheets 解题报告
- CODEFORCES:1B. Spreadsheets
- 暑期集训Day2训练赛D题Spreadsheets(codeforces 1B)
- Codeforces 1B. Spreadsheets
- Codeforces 1B. Spreadsheets
- Codeforces_1B_Spreadsheets
- CodeForces 1B. Spreadsheets(模拟)
- codeforces-1B. Spreadsheets
- codeforces--Spreadsheets(模拟)
- 【codeforces 1B】Spreadsheets——模拟,水
- codeforces--Spreadsheets(模拟)
- codeforces-1B-Spreadsheets( C++ && PHP && 字符串操作 && 数学逻辑 )
- codeforces - 1B - Spreadsheets
- codeforces 461C
- Codeforces_116A
- CodeForces 131B
- Codeforces 198E
- Codeforces - 831C. Jury Marks - 暴力+二分
- CodeForces - 651B 一个简单的思考题,暴力也能过
- 【杂题】 codeforces 142B Help General