CodeForces - 1B Spreadsheets
2014-11-05 21:39
316 查看
模拟Excel表格的行和列。。
其实就是十进制和二十六进制的转换,只不过二十六进制没有零元。。
在CF上看见了大神写的代码,赶紧贴上,膜拜一下。代码能力太差了......
这是练习赛的时候写的代码。没有整理,显得很乱。
其实就是十进制和二十六进制的转换,只不过二十六进制没有零元。。
在CF上看见了大神写的代码,赶紧贴上,膜拜一下。代码能力太差了......
#include <cstdio> void fun(int x) { if(x) { fun((x-1)/26); printf("%c", (x-1)%26+'A'); } } int main() { int n, i; scanf("%d%*c", &n); while(n--) { char s[600], *p; int x, y; gets(s); if(sscanf(s, "%*c%d%*c%d", &x, &y)==2) { fun(y); printf("%d\n", x); } else { for(x=0, p=s; *p>64; p++) x=x*26+*p-64; printf("R%sC%d\n", p, x); } } return 0; }
这是练习赛的时候写的代码。没有整理,显得很乱。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <vector> #include <list> #include <queue> #include <stack> #include <sstream> using namespace std; int n; string str; int judge() { int cnt=0, sign=0; for(int i=0; i<str.length(); i++) if(str[i]>='A' && str[i]<='Z') { if(sign==0) cnt++, sign=1;; } else sign=0; return cnt; } int main() { cin>>n; while(n--) { cin>>str; int op=judge(); if(op==1) { cout<<"R"; int num=0, i; for(i=0; str[i]>='A' && str[i]<='Z'; i++) num=num*26+str[i]-'A'+1; for(; i<str.length(); i++) cout<<str[i]; cout<<"C"<<num<<endl; } else { int sign=0, num=0; for(int i=0; i<str.length(); i++) { if(str[i]=='C') sign=1; if(sign && str[i]>='0' && str[i]<='9') num=num*10+str[i]-'0'; } vector<int> v; v.clear(); while(num) { v.push_back((num-1)%26); num=(num-1)/26; } for(int i=v.size()-1; i>=0; i--) printf("%c", v[i]+'A'); for(int i=1; i<str.length(); i++) { if(str[i]=='C') break; cout<<str[i]; } cout<<endl; } } return 0; }
相关文章推荐
- Codeforces 1B Spreadsheets(模拟+26进制思想)
- CodeForces 1B Spreadsheets(EXCEL)
- CodeForces 1B Spreadsheets (字符串处理,注意细节,大胆尝试)
- CodeForces 1B Spreadsheets
- CodeForces 1B Spreadsheets
- CodeForces 1B Spreadsheets(模拟)
- CodeForces 1B Spreadsheets(模拟)
- Spreadsheets
- Accessing Excel Spreadsheets via C++
- codeforces B Spreadsheets
- google spreadsheets试用
- Microsoft Office Excel 2007 Programming: Your visual blueprint for creating interactive spreadsheets
- Extract tables from messy spreadsheets with jailbreakr
- Codeforces 777C Alyona and Spreadsheet
- Google Docs & Spreadsheets 正式上线了!
- Creating Spreadsheets and Charts in Microsoft Office Excel 2007 for Windows: Visual QuickProject Gui
- Google推出的新服务:Docs & Spreadsheets
- Excel Hacks: Tips & Tools for Streamlining Your Spreadsheets
- codeforces 777C Alyona and Spreadsheet(DP+思维)
- Codeforces 1B Spreadsheet