# Task
 John is new to spreadsheets. He is well aware of rows and columns, but he is not comfortable with spreadsheets numbering system.
```
Spreadsheet             Row Column
A1                      R1C1
D5                       R5C4
AA48                    R48C27
BK12                   R12C63```
Since John has a lot of work to do both in row-column and spreadsheet systems, he needs a program that converts cell numbers from one system to another.


# Example

 For `s = "A1"`, the result should be `"R1C1"`.

 For `s = "R48C27"`, the result should be `"AA48"`.
 
- Input/Output


 - `[input]` string `s`

  The position (in spreadsheet or row-column numbering system).

  `Spreadsheet : A1 to CRXO65535`
  
  `Row-Column: R1C1 to R65535C65535`
  
  
 - `[output]` a string

  The position (in the opposite format; if input was in spreadsheet system, the output should be int row-column system, and vise versa).

Difficulty: EASY
Starter code: def spreadsheet(s):
	

Solutions:
import re

def spreadsheet(s):
	nums = re.findall('(\\d+)', s)
	if len(nums) == 2:
		(n, cStr) = (int(nums[1]), '')
		while n:
			(n, r) = divmod(n - 1, 26)
			cStr += chr(r + 65)
		return '{}{}'.format(cStr[::-1], nums[0])
	else:
		return 'R{}C{}'.format(nums[0], sum((26 ** i * (ord(c) - 64) for (i, c) in enumerate(re.sub('\\d', '', s)[::-1]))))


def spreadsheet(s):
	try:
		(r, c) = map(int, s[1:].split('C'))
		l = str(r)
		while c:
			(c, i) = divmod(c - 1, 26)
			l = chr(i + 65) + l
		return l
	except:
		c = 0
		for (i, l) in enumerate(s):
			if l.isdigit():
				break
			c = 26 * c + ord(l) - 64
		return 'R%sC%d' % (s[i:], c)


import re
from string import ascii_uppercase as ALPHA

def num2alpha(num, b=len(ALPHA), numerals=ALPHA):
	return '' if not num else num2alpha((num - 1) // b, b, numerals) + numerals[(num - 1) % b]

def alpha2num(string, b=len(ALPHA), numerals=ALPHA):
	return sum(((numerals.index(v) + 1) * b ** i for (i, v) in enumerate(reversed(string))))
rcregex = re.compile('R(\\d+)C(\\d+)')
spregex = re.compile('([A-Z]+)(\\d+)')

def spreadsheet(s):
	m = rcregex.match(s)
	if m:
		return num2alpha(int(m.group(2))) + m.group(1)
	m = spregex.match(s)
	if m:
		return 'R{}C{}'.format(m.group(2), alpha2num(m.group(1)))
	return ''


import re

def spreadsheet(s):
	numbers = re.findall('(\\d+)', s)
	if len(numbers) == 1:
		row = numbers[0]
		col = sum((26 ** i * (ord(v) - 64) for (i, v) in enumerate(s[:s.find(row)][::-1])))
		return 'R{row}C{col}'.format(row=row, col=col)
	else:
		row = numbers[0]
		x = int(numbers[1])
		col = ''
		while x > 0:
			col = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[(x - 1) % 26] + col
			x = (x - 1) // 26
		return '{col}{row}'.format(col=col, row=row)


import string
import re

def spreadsheet(s):
	if re.match('^R\\d+C\\d+$', s):
		return convert_to_ss(s)
	else:
		return convert_to_rc(s)

def convert_to_rc(s: str) -> str:
	ind = re.search('\\d', s).span()[0]
	letters = s[:ind]
	nums = s[ind:]
	cols = 0
	for i in range(len(letters)):
		if i != len(letters) - 1:
			cols += (string.ascii_uppercase.find(letters[i]) + 1) * 26 ** (len(letters) - i - 1)
		else:
			cols += string.ascii_uppercase.find(letters[i]) + 1
	return f'R{nums}C{cols}'

def convert_to_ss(s: str) -> str:
	ind = s.find('C')
	rows = s[1:ind]
	cols = int(s[ind + 1:])
	res_col = ''
	while cols > 0:
		(cols, rem) = (cols // 26, cols % 26)
		if res_col and res_col[0] == 'Z':
			if rem == 1:
				break
			else:
				res_col = string.ascii_uppercase[rem - 2] + res_col
		else:
			res_col = string.ascii_uppercase[rem - 1] + res_col
		print(cols, rem)
	return f'{res_col}{rows}'


from itertools import product
from string import ascii_uppercase as ap
import re
transo = list(map(lambda x: ''.join(x), list(ap) + list(product(ap, repeat=2)) + list(product(ap, repeat=3)) + list(product(ap, repeat=4))))

def spreadsheet(no):
	matches = re.match('(?P<RC1>^R\\d+C\\d+$)|(?P<A1>^(?P<LET>[A-Z]+)\\d+$)', no)
	if matches.group('RC1'):
		asi = matches.group('RC1')
		asiind = asi.index('C')
		return transo[int(asi[asiind + 1:]) - 1] + asi[1:asiind]
	else:
		asi = matches.group('LET')
		df = transo.index(asi)
		return f'R{no[no.rfind(asi) + len(asi):]}C{df + 1}'


import re
from string import ascii_uppercase as upper

def spreadsheet(s):
	x = re.search('^([A-Z]+)(\\d+)$', s)
	if x:
		(c, r) = x.groups()
		return f'R{r}C{sum(((upper.index(j) + 1) * 26 ** (len(c) - i - 1) for (i, j) in enumerate(c)))}'
	else:
		(r, c) = re.search('(?:R)(\\d+)(?:C)(\\d+)', s).groups()
		(s, c) = ([], int(c))
		if c == 26:
			return 'Z' + r
		while c > 1:
			(c, m) = divmod(c, 26)
			s.append([c, m])
		return ['', 'A'][c] + ''.join([upper[s[i][1] - ([2, 1][bool(s[i - 1][1])] if i > 0 else 1)] for i in range(len(s))])[::-1] + r


import re

def spreadsheet(s):
	m = re.match('([A-Z]+)(\\d+)$', s)
	if m:
		(c, r) = (m.group(1), int(m.group(2)))
		column = 0
		for d in c:
			column = column * 26 + (ord(d) - ord('A') + 1)
		return 'R{}C{}'.format(r, column)
	else:
		m = re.match('R(\\d+)C(\\d+)$', s)
		(r, c) = (m.group(1), int(m.group(2)))
		column = ''
		while c > 0:
			m = c % 26
			if m == 0:
				m = 26
			column = chr(ord('A') + m - 1) + column
			c = (c - m) // 26
		return column + r


import re

def to_display(b, n):
	r = []
	while n:
		(n, x) = divmod(n - 1, 26)
		r.append(chr(65 + x))
	return ''.join(r[::-1]) + str(b)

def to_internal(s):
	((a, b), n) = (re.findall('[A-Z]+|\\d+', s), 0)
	for x in a:
		n *= 26
		n += ord(x) - 64
	return (int(b), n)

def spreadsheet(s):
	a = re.findall('[A-Z]+|\\d+', s)
	return 'R{}C{}'.format(*to_internal(s)) if len(a) == 2 else to_display(int(a[1]), int(a[3]))


from re import fullmatch, findall

def spreadsheet(s):
	if fullmatch('R\\d+C\\d+', s):
		row = findall('\\d+', s)[0]
		col = findall('\\d+', s)[1]
		return f'{convert_int(col)}{row}'
	else:
		row = findall('\\d+', s)[0]
		col = findall('[A-Z]+', s)[0]
		return f'R{row}C{convert_str(col)}'

def convert_int(num, to_base=26, from_base=10):
	if isinstance(num, str):
		n = int(num, from_base)
	else:
		n = int(num)
	alphabet = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	if n <= to_base:
		return alphabet[n]
	elif n % to_base == 0:
		return convert_int(n // to_base - 1, to_base) + alphabet[26]
	else:
		return convert_int(n // to_base, to_base) + alphabet[n % to_base]

def convert_str(num):
	num = list(num)[::-1]
	answer = 0
	alphabet = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	for i in range(len(num)):
		answer += alphabet.index(num[i]) * 26 ** int(i)
	return answer