Given an IP address, remove leading zeros from the IP address. Note that our IP address here can be a little different. It can have numbers greater than 255. Also, it does not necessarily have 4 numbers. The count can be lesser/more.
Example 1:
Input:
S = "100.020.003.400"
Output: 100.20.3.400
Explanation: The leading zeros are removed
from 20 and 3.
Example 2:
Input: 
S = "100.000.010.0999"
Output: 100.0.10.999
Explanation: The leading zeros are removed
from 0, 10 and 999.
Your Task:
You don't need to read input or print anything. Your task is to complete the function newIPAdd() which takes the string S representing the IP address as input and returns a string representing the resultant IP address. 
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(|S|).
Constraints:
1<=|S|<=1000

Difficulty: MEDIUM
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(|S|).

Starter code:
#User function Template for python3



class Solution:

    def newIPAdd(self, S):

        # code here

Solutions:
class Solution:

	def newIPAdd(self, S):
		ans = ''
		flag = 0
		count = 0
		for i in S:
			if i != '.' and (flag == 1 or i != '0'):
				ans = ans + i
				flag = 1
			elif i == '.':
				if flag == 0:
					ans = ans + '0'
				ans = ans + '.'
				flag = 0
		if flag == 0:
			ans = ans + '0'
		return ans


class Solution:

	def newIPAdd(self, S):
		S = S.split('.')
		b = []
		for i in S:
			e = int(i)
			b.append(str(e))
		return '.'.join(b)


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		j = []
		k = []
		for i in l:
			k.append(str(int(i)))
		j = '.'.join(k)
		return j


class Solution:

	def newIPAdd(self, S):
		li = S.split('.')
		b = []
		for i in li:
			x = int(i)
			b.append(x)
			b.append('.')
		z = ''
		for i in b:
			z += str(i)
		return z[:len(z) - 1]


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		a = ''
		for i in l:
			if len(set(i)) == 1 and i[0] == '0':
				a += '0.'
			else:
				for j in range(len(i)):
					if i[j] != '0':
						a += i[j:]
						a += '.'
						break
		a = list(a)
		a.pop()
		return ''.join(a)


class Solution:

	def newIPAdd(self, S):
		ip = list(map(int, S.split('.')))
		return '.'.join(map(str, ip))


class Solution:

	def newIPAdd(self, S):
		m = S.split('.')
		list1 = [int(i) for i in m]
		list2 = [str(i) for i in list1]
		p = '.'.join(list2)
		return p


class Solution:

	def newIPAdd(self, S):
		c = 0
		ans = ''
		for i in range(0, len(s)):
			if s[i] == '.':
				ans += str(c)
				c = 0
				ans += '.'
			else:
				c = c * 10 + (ord(s[i]) - 48)
		ans += str(c)
		return ans


class Solution:

	def newIPAdd(self, s):
		i = 0
		x = ''
		f = 0
		ans = ''
		while i < len(s):
			if s[i] == '.':
				f = 1
				x += s[i]
			elif f == 1 and s[i] == '0':
				f = 1
			else:
				x += s[i]
				f = 0
			i += 1
		i = 0
		g = 0
		if x[i] == '0':
			while i < len(x) and x[i] != '.':
				if g == 1 or x[i] != '0':
					ans += x[i]
					g = 1
				i += 1
			if ans == '':
				ans += '0'
		j = i
		while j < len(x):
			if x[j] == '.':
				if j + 1 < len(x) and x[j + 1] == '.':
					ans += x[j]
					ans += '0'
				else:
					ans += x[j]
			else:
				ans += x[j]
			j += 1
		if ans[-1] == '.':
			ans += '0'
		return ans


class Solution:

	def newIPAdd(self, s):
		lst = s.split('.')
		return '.'.join((str(int(elem)) for elem in lst))


class Solution:

	def newIPAdd(self, S):
		S = S.split('.')
		r = ''
		for i in range(len(S)):
			r += str(int(S[i]))
			r += '.'
		return r[:len(r) - 1]


class Solution:

	def newIPAdd(self, S):
		ans = ''
		temp_list = []
		temp_list = S.split('.')
		temp_list = [int(x) for x in temp_list]
		temp_list = [str(x) for x in temp_list]
		ans = '.'.join(temp_list)
		return ans


class Solution:

	def newIPAdd(self, S):
		s = S.split('.')
		a = []
		for i in s:
			a.append(int(i))
		j = ''
		f = '.'
		for i in a:
			j += str(i) + f
		return j[:-1]


class Solution:

	def newIPAdd(self, S):
		S = '.' + S + '.'
		while '.0' in S:
			S = S.replace('.0', '.')
		while '..' in S:
			S = S.replace('..', '.0.')
		return S[1:-1]


class Solution:

	def newIPAdd(self, S):
		ar = s.split('.')
		news = ''
		for i in ar:
			news += str(int(i)) + '.'
		lens = len(news) - 1
		return news[:lens]


class Solution:

	def newIPAdd(self, s):
		s = s.split('.')
		ans = []
		for x in s:
			x = x.lstrip('0')
			if len(x) == 0:
				ans.append('0')
			else:
				ans.append(x)
		return '.'.join(ans)


class Solution:

	def newIPAdd(self, S):
		p = S.split('.')
		q = ''
		for i in range(len(p)):
			if p[i].isdigit() and i < len(p) - 1:
				d = int(p[i])
				q += str(d) + '.'
			else:
				d = int(p[i])
				q += str(d)
		return q


class Solution:

	def newIPAdd(self, S):
		S = S.split('.')
		for i in range(len(S)):
			S[i] = str(int(S[i]))
		return '.'.join(S)


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		ss = ''
		for i in l:
			p = i.lstrip('0')
			if len(p) == 0:
				p = '0'
			ss += p + '.'
		return ss[:-1]


class Solution:

	def newIPAdd(self, S):
		numbers1 = S.split('.')
		numbers2 = []
		for number in numbers1:
			a = int(number)
			numbers2.append(a)
		numbers2 = [str(i) for i in numbers2]
		s = '.'.join(numbers2)
		return s


class Solution:

	def newIPAdd(self, S):
		mylist = S.split('.')
		newlist = []
		for e in mylist:
			temp = e.lstrip('0')
			if temp == '':
				newlist.append('0')
			else:
				newlist.append(temp)
		return '.'.join(newlist)


class Solution:

	def newIPAdd(self, S):
		arr = s.split('.')
		ans = ''
		for el in arr:
			ans += str(int(el)) + '.'
		a = len(ans) - 1
		return ans[:a]


class Solution:

	def newIPAdd(self, S):
		ans = ''
		for i in S.split('.'):
			ans += str(int(i)) + '.'
		return ans[0:len(ans) - 1]


class Solution:

	def newIPAdd(self, S):
		l = [int(i) for i in S.split('.')]
		return '.'.join(map(str, l))


class Solution:

	def newIPAdd(self, S):
		return '.'.join([str(int(item)) for item in S.split('.')])


class Solution:

	def newIPAdd(self, S):
		s = S.split('.')
		s = [int(i) for i in s]
		s = [str(i) for i in s]
		return '.'.join(s)


class Solution:

	def newIPAdd(self, S):
		new_list = S.split('.')
		final_list = []
		for i in new_list:
			num = int(i)
			final_list.append(str(num))
		final = '.'.join(final_list)
		return final


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		res = ''
		for i in l:
			i = int(i)
			s = str(i)
			res += s + '.'
		res = res[:-1]
		return res


class Solution:

	def newIPAdd(self, S):
		data = S.split('.')
		for i in range(len(data)):
			if data[i][0] == '0':
				p = 0
				j = 0
				while p < len(data[i]):
					if data[i][p] != '0':
						j = 1
					if j == 1:
						break
					else:
						data[i] = data[i][1:]
				if len(data[i]) == 0:
					data[i] = '0'
		strx = ''
		for i in range(len(data)):
			if i == len(data) - 1:
				strx = strx + data[i]
			else:
				strx = strx + data[i] + '.'
		return strx


class Solution:

	def newIPAdd(self, S):
		s1 = S.split('.')
		rem = ''
		for i in s1:
			rem += str(int(i)) + '.'
		return rem[:-1]


class Solution:

	def newIPAdd(self, S):
		u = []
		for j in range(len(S)):
			if S[j] == '.':
				u.append(j)
		v = []
		for k in range(1, len(u)):
			x = u[k - 1] + 1
			y = u[k]
			e = S[x:y]
			v.append(e)
		x = u[0]
		y = u[-1]
		e = [S[:x]] + v + [S[y + 1:]]
		e = list(map(int, e))
		e = list(map(str, e))
		s = ''
		for j in range(len(e)):
			s = s + e[j] + '.'
		f = len(s)
		s = s[:f - 1]
		return s


class Solution:

	def newIPAdd(self, S):
		address = [add.lstrip('0') for add in S.split('.')]
		res = ''
		for add in address:
			if add == '':
				res += '.0'
			else:
				res += '.' + add
		return res[1:]


class Solution:

	def newIPAdd(self, S):
		ans = ''
		c = ''
		for i in s:
			if i == '.':
				c = int(c)
				ans += str(c)
				ans += '.'
				c = ''
			else:
				c += i
		c = int(c)
		ans += str(c)
		return ans


class Solution:

	def newIPAdd(self, S):
		nums = S.split('.')
		ans = ''
		for item in nums:
			num = int(item)
			ans = ans + str(num)
			ans = ans + '.'
		return ans[:-1]


class Solution:

	def newIPAdd(self, S):
		p = S.split('.')
		s = ''
		for i in p:
			j = int(i)
			s += str(j)
			s += '.'
		return s[:len(s) - 1]


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		for i in range(len(l)):
			l[i] = l[i].lstrip('0')
			if len(l[i]) == 0:
				l[i] = '0'
		return '.'.join(l)


class Solution:

	def newIPAdd(self, S):
		sub_s = ''
		ans = ''
		for i in range(len(s)):
			if S[i] == '.':
				ans += str(int(sub_s)) + S[i]
				sub_s = ''
			elif i == len(S) - 1:
				ans += str(int(sub_s + S[i]))
			else:
				sub_s += S[i]
		return ans


class Solution:

	def newIPAdd(self, S):
		lst = list(S.split('.'))
		ans = ''
		for i in lst:
			ans += str(int(i))
			ans += '.'
		return ans[:len(ans) - 1]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		seperator = '.'
		arr = S.split('.')
		for x in range(len(arr)):
			arr[x] = int(arr[x])
		s = ''
		for x in arr:
			s += str(x) + seperator
		s = s[:-1]
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		a = S.split('.')
		for i in range(len(a)):
			t = list(a[i])
			count = 1
			if t[0] == '0':
				if len(t) > 2 and t[0] == t[1]:
					for j in range(len(t) - 2):
						if t[j] == '0' and t[j + 1] == '0':
							count += 1
						else:
							break
					if count > 0:
						t = t[count:]
				elif len(t) > 1:
					t[0] = ''
			a[i] = ''.join(t)
		return '.'.join(a)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		u = []
		for j in range(len(S)):
			if S[j] == '.':
				u.append(j)
		v = []
		for k in range(1, len(u)):
			x = u[k - 1] + 1
			y = u[k]
			e = S[x:y]
			v.append(e)
		x = u[0]
		y = u[-1]
		e = [S[:x]] + v + [S[y + 1:]]
		e = list(map(int, e))
		e = list(map(str, e))
		s = ''
		for j in range(len(e)):
			s = s + e[j] + '.'
		f = len(s)
		s = s[:f - 1]
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		lst = S.split('.')
		lst1 = []
		s = ''
		for i in lst:
			k = int(i)
			lst1.append(k)
		c = 0
		for i in lst1:
			h = str(i)
			if c == 0:
				s = s + h
				c = 1
			else:
				s = s + '.' + h
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		nums = s.split('.')
		res_ip = []
		for num in nums:
			if num.count('0') == len(num):
				res_ip.append('0')
			else:
				res_ip.append(num.lstrip('0'))
		return '.'.join(res_ip)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, s):
		ar = s.split('.')
		news = ''
		for i in ar:
			news += str(int(i)) + '.'
		lens = len(news) - 1
		return news[:lens]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		ip = S.split('.')
		sNew = []
		for i in ip:
			temp = int(i)
			temp = str(temp)
			sNew.append(temp)
		x = '.'.join(sNew)
		return x
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		a = S.split('.')
		b = []
		for i in a:
			i = int(i)
			i = str(i)
			b.append(i)
		c = '.'.join(b)
		return c
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		arr = S.split('.')
		for i in range(len(arr)):
			arr[i] = str(int(arr[i]))
		return '.'.join(arr)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input().strip()
		ob = Solution()
		ans = ob.newIPAdd(s)
		print(ans)


class Solution:

	def newIPAdd(self, S):
		arr = s.split('.')
		st = ''
		for i in arr:
			st += str(int(i)) + '.'
		l = len(st) - 1
		return st[:l]


class Solution:

	def newIPAdd(self, s):
		ans = ''
		firstdot = False
		nonzero = False
		for i in s:
			if firstdot == False:
				if i == '.':
					firstdot = True
					if nonzero == False:
						ans += '0'
					else:
						nonzero = False
					ans += '.'
				elif i != '0':
					nonzero = True
				if nonzero == True:
					ans += i
			else:
				if i == '.':
					if nonzero == False:
						ans += '0'
					else:
						nonzero = False
					ans += '.'
				elif i != '0':
					nonzero = True
				if nonzero == True:
					ans += i
		if nonzero == False:
			ans += '0'
		return ans


class Solution:

	def newIPAdd(self, s):
		s = s.split('.')
		for i in range(len(s)):
			s[i] = int(s[i])
		return '.'.join(map(str, s))


class Solution:

	def newIPAdd(self, s):
		s = s.split('.')
		lst = []
		for i in s:
			lst.append(str(int(i)))
		res = '.'.join(lst)
		return res


class Solution:

	def newIPAdd(self, S):
		k = S.split('.')
		for i in range(0, len(k)):
			if len(k[i]) > 1:
				k[i] = int(k[i])
				k[i] = str(k[i])
		res = k[0]
		for i in range(1, len(k)):
			res = res + '.' + k[i]
		return res


class Solution:

	def newIPAdd(self, S):
		c = ''
		p = 1
		for i in S:
			if p == 1:
				if i == '.':
					if len(c) == 0:
						c = c + '0'
						c = c + i
						continue
				if i == '0':
					continue
				else:
					if len(c) > 0:
						if c[-1] == '.' and i == '.':
							c = c + '0' + i
							p = 1
							continue
					c = c + i
					p = 0
				continue
			else:
				p = 0
				if i == '.':
					p = 1
				c = c + i
		if c[-1] == '.' and i == '0':
			c = c + '0'
		return c


class Solution:

	def newIPAdd(self, S):
		a = S.split('.')
		c = []
		for i in range(len(a)):
			x = int(a[i])
			y = str(x)
			c.append(y)
		d = '.'.join(c)
		return d


class Solution:

	def newIPAdd(self, S):
		(S, ans) = (S.split('.'), '')
		for ad in S:
			ans += str(int(ad)) + '.'
		return ans[:-1]


class Solution:

	def newIPAdd(self, S):
		list1 = list(S.split('.'))
		list2 = []
		for i in list1:
			if i in ('0', '00', '000'):
				list2.append('0')
			else:
				list2.append(i.lstrip('0'))
		return '.'.join(list2)


class Solution:

	def newIPAdd(self, S):
		L = S.split('.')
		L = [int(x) for x in L]
		L = [str(x) for x in L]
		return '.'.join(L)


class Solution:

	def newIPAdd(self, s):
		l = list(map(int, s.split('.')))
		l = [str(x) for x in l]
		return '.'.join(l)


class Solution:

	def newIPAdd(self, S):
		data = S.split('.')
		str1 = data[0]
		str2 = data[1]
		str3 = data[2]
		str4 = data[3]
		for i in range(len(data)):
			if data[i][0] == '0':
				p = 0
				j = 0
				while p < len(data[i]):
					if data[i][p] != '0':
						j = 1
					if j == 1:
						break
					else:
						data[i] = data[i][1:]
				if len(data[i]) == 0:
					data[i] = '0'
		strx = ''
		for i in range(len(data)):
			if i == len(data) - 1:
				strx = strx + data[i]
			else:
				strx = strx + data[i] + '.'
		return strx
		ans = str1 + '.' + str2 + '.' + str3 + '.' + str4
		return ans


class Solution:

	def newIPAdd(self, S):
		rs = ''
		for word in S.split('.'):
			if int(word):
				rs += word.lstrip('0') + '.'
			else:
				rs += '0' + '.'
		return rs[:-1]


class Solution:

	def newIPAdd(self, S):
		return '.'.join((word.lstrip('0') if int(word) else '0' for word in S.split('.')))


class Solution:

	def newIPAdd(self, S):
		ans = []
		for i in S.split('.'):
			ans.append(str(int(i)))
		return '.'.join(ans)


class Solution:

	def newIPAdd(self, S):
		s = ''
		l = list(S.split('.'))
		for i in range(len(l)):
			l1 = list(l[i])
			idx = -1
			for j in range(len(l1)):
				if l1[j] == '0':
					pass
				else:
					idx = j
					break
			if idx != -1:
				s += l[i][idx:] + '.'
			else:
				s += '0' + '.'
		return s[:len(s) - 1]


class Solution:

	def newIPAdd(self, S):
		ans = ''
		a = S.split('.')
		for i in a:
			a = int(i)
			ans += str(a)
			ans += '.'
		return ans[:-1]


class Solution:

	def newIPAdd(self, S):
		lst = s.split('.')
		lst = [elem.lstrip('0') for elem in lst]
		for (i, elem) in enumerate(lst):
			if elem == '':
				lst.remove(elem)
				lst.insert(i, '0')
		return '.'.join(lst)


class Solution:

	def newIPAdd(self, S):
		S = S + '.'
		s1 = ''
		ans = ''
		for i in S:
			if i == '.':
				q = int(s1)
				temp = str(q)
				ans = ans + temp
				ans = ans + '.'
				s1 = ''
			else:
				s1 = s1 + i
		return ans[:len(ans) - 1]


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		for (i, j) in enumerate(l):
			l[i] = int(j)
		s = ''
		for x in l:
			s += str(x) + '.'
		return s[:-1]


class Solution:

	def newIPAdd(self, S):
		s = S.split('.')
		string = ''
		for i in range(len(s) - 1):
			string = string + str(int(s[i])) + '.'
		string = string + str(int(s[len(s) - 1]))
		return string


class Solution:

	def newIPAdd(self, S):
		l = S.split('.')
		res = []
		for i in l:
			res.append(str(int(i)))
		return '.'.join(res)


class Solution:

	def newIPAdd(self, S):
		A = []
		num = ''
		for i in S:
			if i != '.':
				num += i
			else:
				A.append(int(num))
				num = ''
		A.append(int(num))
		result = ''
		for i in A:
			result += str(i) + '.'
		return result[:-1]


class Solution:

	def newIPAdd(self, s):
		a = s.split('.')
		a = list(map(int, a))
		for i in a:
			a = 1 * a
		a = list(map(str, a))
		s = '.'.join(a)
		return s


class Solution:

	def newIPAdd(self, S):
		a = S.split('.')
		r = []
		for i in a:
			r.append(str(int(i)))
		return '.'.join(r)


class Solution:

	def newIPAdd(self, S):
		arr = S.split('.')
		res = ''
		for i in arr:
			if i[0] != '0':
				res += i + '.'
				continue
			if '0' * len(i) == i:
				res += '0.'
				continue
			else:
				temp = ''
				for j in range(0, len(i)):
					if i[j] == '0':
						continue
					if j != '0':
						res += i[j:] + '.'
						break
		return res[0:-1]


class Solution:

	def newIPAdd(self, S):
		s = ''
		ms = ''
		f = True
		for i in S:
			if i == '.':
				if s == '':
					ms += '0.'
				else:
					ms += s + '.'
				s = ''
				f = True
			elif f == True and i == '0':
				pass
			else:
				f = False
				s += i
		if s == '':
			ms += '0.'
		else:
			ms += s + '.'
		s = ''
		return ms[:-1]


class Solution:

	def newIPAdd(self, S):
		res = ''
		l = list(s.split('.'))
		for i in range(len(l)):
			if i != len(l) - 1:
				res += str(int(l[i])) + '.'
			else:
				res += str(int(l[i]))
		return res


class Solution:

	def newIPAdd(self, S):
		chars = [str(int(x)) for x in S.split(sep='.')]
		return '.'.join(chars)


class Solution:

	def newIPAdd(self, S):
		res = S.split('.')
		don = []
		for part in res:
			st = str(int(part))
			don.append(st)
		return '.'.join(don)