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
Belphegor 90 points

                                    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')

4.2 (10 Votes)
0
3
2
Kyeotic 80 points

                                    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))

3 (2 Votes)
0
3.5
2
Cristina 85 points

                                    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)

3.5 (2 Votes)
0
4.4
5
Neisantos 125 points

                                    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.4 (5 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source