WOJ1115-An Excel-lent Problem
2017-09-03 19:39
197 查看
A certain spreadsheet program labels the columns of a spreadsheet using letters. Column 1 is labeled as
26
as
The rows in the spreadsheet are labeled using the row number. Rows start at 1.
The designation for a particular cell within the spreadsheet is created by combining the column label with the row label. For example, the
upper-left most cell would be
You will write a program that converts numeric row and column values into the spreadsheet designation.
Input consists of lines of the form: RnCm. n represents the row number [1,300000000] and m represents the column number, 1<=m<=300000000. The
values n and m define a single cell on the spreadsheet. Input terminates with the line: R0C0 (that is, n and m are 0). There will be no
leading zeroes or extra spaces in the input.
For each line of input (except the terminating line), you will print out the spreadsheet designation for the specified cell as described above.
水题,照题意仔细做就行
A", column 2 asB", ..., column
26
as
Z". When the number of columns is greater than 26, another letter is used. For example, column 27 isAA", column 28 is
AB" and column <br/>52 isAZ". It follows that column 53 would be
BA" and so on. Similarly, when columnZZ" is reached, the next column would be
AAA", <br/>thenAAB" and so on.
The rows in the spreadsheet are labeled using the row number. Rows start at 1.
The designation for a particular cell within the spreadsheet is created by combining the column label with the row label. For example, the
upper-left most cell would be
A1". The cell at column 55 row 23 would beBC23".
You will write a program that converts numeric row and column values into the spreadsheet designation.
输入格式
Input consists of lines of the form: RnCm. n represents the row number [1,300000000] and m represents the column number, 1<=m<=300000000. Thevalues n and m define a single cell on the spreadsheet. Input terminates with the line: R0C0 (that is, n and m are 0). There will be no
leading zeroes or extra spaces in the input.
输出格式
For each line of input (except the terminating line), you will print out the spreadsheet designation for the specified cell as described above.
样例输入
R1C1 R3C1 R1C3 R299999999C26 R52C52 R53C17576 R53C17602 R0C0
样例输出
A1 A3 C1 Z299999999 AZ52 YYZ53 YZZ53
水题,照题意仔细做就行
#include <iostream> #include <stdio.h> using namespace std; char f[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; int bin[10]; int main(){ int r,c,i,j; while(~scanf("R%dC%d%*c",&r,&c)){ if(!r&&!c)break; int cnt=0; while(c){ bin[cnt++]=c%26; if(bin[cnt-1]==0){ bin[cnt-1]=26; c--; } c/=26; } for(i=cnt-1;i>=0;i--) printf("%c",f[bin[i]-1]); printf("%d\n",r); } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true) { String input = in.nextLine(); if(input.equals("R0C0")) 4000 break; int index = 0; while(input.charAt(index)!='C') { index++; } int num = Integer.parseInt(input.substring(1, index)); int letter = Integer.parseInt(input.substring(index+1, input.length())); String result = ""; result = change(letter) + result; while(true) { if(letter/26.0>1) { if(letter%26!=0) { letter = letter/26; result = change(letter) + result; } else { letter = letter/26; letter--; result = change(letter) + result; } } else break; } System.out.println(result+num); } } public static char change(int letter) { char m; if(letter % 26 == 0) m = 'Z'; else m = (char) (letter%26 + 'A' -1); return m; } }
相关文章推荐
- poj 2273 An Excel-lent Problem 类进制转换
- poj 2273 An Excel-lent Problem(进制转换)
- TOJ 2102 An Excel-lent Problem 进制转换
- PHPExcel_Reader_Exception: is not recognised as an OLE file in Classes
- Creating excel sheets through php with an image
- EXCEL caused an invalid page fault in
- Select data from an Excel sheet in MSSQL
- Joining an array of keys to a hash with key value pairs like excel vlookup
- How to transfer data to an Excel workbook by using Visual C# 2005 or Visual C# .NET
- To upload an excel file using WebDynpro Application.
- How to use an ActiveX script task to import data into a new Excel file
- linux导出Excel The maximum column width for an individual cell is 255 characters
- 在excel中创建sheet的索引 Use index sheets to quickly navigate in an Excel workbook
- Dynamics AX 2009: Ad hoc Analysis using Excel 2007 to get data from an AX OLAP Cube
- ASP.NET: Dispaly data from an Excel Spreadsheet
- Export GridView to Excel within an UpdatePanel
- PHPExcel的exception 'Exception' with message 'The filename is not recognised as an OLE file问题解决
- ASP.NET datagrid直接导出为Excel Export to Excel from DataGrid (Using an Microsoft Access database)
- oledb 处理excel 报错 UPDATE “Operation must use an updateable query”
- ASP.NET: Dispaly data from an Excel Spreadsheet