online python to c++ compiler
s = input()
op = ''
for i in range(len(s)-1):
if s[i]==s[i+1]:
op += s[i]
op += '*'
else:
op += s[i]
op += s[-1]
print(op)
4.2
10
graph = {'S':{'A':1, 'C':2}, 'A':{'B':6}, 'B':{'D':1, 'E':2}, 'C':{'A':4, 'D':3}, 'D':{'E':1}, 'E':{}} #we illustrate the dijkstra graph
def dijkstra(graph,start,target):
# we set all the default value first for all variable
shortest_distance = {}
previous = {}
unvisitNodes = graph
infinity = 999999999
pathway = []
# for loop to check wether node have visit or not
# if the node in unvisit nodes, set the shortest distance for the node to infinity
# Set the shortest distance for start node to 0
for node in unvisitNodes:
shortest_distance[node] = infinity
shortest_distance[start] = 0
# while loop to decide the next node will be visit
# for first time around, it start with start node (itself)
#
while unvisitNodes:
minNode = None
for node in unvisitNodes:
if minNode is None:
minNode = node
elif shortest_distance[node] < shortest_distance[minNode]:
minNode = node
# for loop to calculate shortest distance target node form start node
# update the short distance target node from start node if calculate distance is less than known distance
# initialize the previous node for each calculate node
# decide the next node will be visit by the smallest known distance from start vertex
# add the node into visited node
for neighbourNode, weight in graph[minNode].items():
if weight + shortest_distance[minNode] < shortest_distance[neighbourNode]:
shortest_distance[neighbourNode] = weight + shortest_distance[minNode]
previous[neighbourNode] = minNode
unvisitNodes.pop(minNode)
#set currentNode into target
currentNode = target
#while loop to list all the path way for the calculate nodes
while currentNode !=start:
try:
pathway.insert(0,currentNode)
currentNode = previous[currentNode]
except KeyError:
print('Path not reach')
break
#add start node into the path way for each calculate nodes
pathway.insert(0,start)
#display the shortest distance and the path way for each target nodes
if shortest_distance[target] != infinity:
print('You are required shortest distance and path:- ')
print('From: ' + str(start))
print('To: ' + str(target))
print('Shortest distance for ' + str(target) + ' from ' + str(start) + ' is ' + str(shortest_distance[target]))
print('The path is ' + str(pathway))
# call the dijkstra function by assign the start and target nodes as the parameter
dijkstra(graph,'S','S')
Thank you!
10
0
3
2
val = input().split(' ')
nums = input().split(' ')
levels = []
for _ in range(int(val[1])):
levels.append(int(input()))
nums = [int(x) for x in nums]
for idx in range(int(val[1])):
r = [x for x in nums if x >= levels[int(idx)]]
print(min(r))
Thank you!
2
0
3.5
2
s = input()
op = ''
for i in range(len(s)-1):
if s[i]==s[i+1]:
op += s[i]
op += '*'
else:
op += s[i]
op += s[-1]
print(op)
Thank you!
2
0
4.4
5
s = input()
op = ''
for i in range(len(s)-1):
if s[i]==s[i+1]:
op += s[i]
op += '*'
else:
op += s[i]
op += s[-1]
print(op)
Thank you!
5
0
Are there any code examples left?
New code examples in category C++
-
C++ 2023-04-28 17:44:25
-
C++ 2022-03-27 19:20:39 lists occurrences of characters in the string c++
-
C++ 2022-03-27 18:00:14 variabili in c++
-
C++ 2022-03-27 17:10:08 repeat character n times c++
-
C++ 2022-03-27 15:50:07 delete an array c++
-
C++ 2022-03-27 15:40:12 C++ pointer to base class
-
C++ 2022-03-27 12:15:21 find the graph is minimal spanig tree or not
-
C++ 2022-03-27 11:30:15 multi variable assignment cpp
-
C++ 2022-03-27 11:05:17 c++ pi float
-
C++ 2022-03-27 10:20:12 why exceptions can lead to memory leaks