0% found this document useful (0 votes)
11 views5 pages

Python Code Snippets-6

The document contains multiple Python and C++ code snippets for various programming tasks. These include counting vowels and consonants in a string, checking if one string is a rotation of another, and implementing sorting algorithms like insertion sort and merge sort. Additionally, there is a PL/SQL snippet for reversing a number.

Uploaded by

jayendrarathod07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Python Code Snippets-6

The document contains multiple Python and C++ code snippets for various programming tasks. These include counting vowels and consonants in a string, checking if one string is a rotation of another, and implementing sorting algorithms like insertion sort and merge sort. Additionally, there is a PL/SQL snippet for reversing a number.

Uploaded by

jayendrarathod07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

# You are using Python

#in the kindom of linguara

s = input().strip()

vowels_set = set("aeiou")

vowels_count = 0

consonants_count = 0

for ch in s.lower():

if ch.isalpha():

if ch in vowels_set:

vowels_count += 1

else:

consonants_count += 1

print(vowels_count, consonants_count)

# You are using Python

#Aarohi

original = input().strip()

received = input().strip()
if len(original) == len(received) and received in (original + original):

print(f"{received} is a rotation of {original}")

else:

print(f"{received} is not a rotation of {original}")

# You are using Python

#Aarohi

original = input().strip()

received = input().strip()

if len(original) == len(received) and received in (original + original):

print(f"{received} is a rotation of {original}")

else:

print(f"{received} is not a rotation of {original}")

// You are using GCC

//Write a program

#include <iostream>

#include <string>

using namespace std;

int main() {

string s;

cin >> s;
string result = "";

int count = 1;

for (size_t i = 1; i < s.size(); i++) {

if (s[i] == s[i - 1]) {

count++;

} else {

result += s[i - 1] + to_string(count);

count = 1;

if (!s.empty()) result += s.back() + to_string(count);

cout << result;

return 0;

Sophie has a

DECLARE

num NUMBER := 1657;

v_reversed_number NUMBER := 0;

rem NUMBER;

BEGIN

WHILE num > 0 LOOP

rem := MOD(num, 10);

v_reversed_number := v_reversed_number * 10 + rem;


num := FLOOR(num / 10);

END LOOP;

# You are using Python

#in the kingdom of Numera

def insertion_sort(arr):

for i in range(1, len(arr)):

key = arr[i]

j=i-1

while j >= 0 and arr[j] > key:

arr[j + 1] = arr[j]

j -= 1

arr[j + 1] = key

return arr

def merge_sort(arr):

if len(arr) <= 1:

return arr

mid = len(arr) // 2

left = merge_sort(arr[:mid])

right = merge_sort(arr[mid:])

return merge(left, right)

def merge(left, right):


result = []

i=j=0

while i < len(left) and j < len(right):

if left[i] <= right[j]:

result.append(left[i])

i += 1

else:

result.append(right[j])

j += 1

result.extend(left[i:])

result.extend(right[j:])

return result

n = int(input().strip())

arr = list(map(int, input().split()))

chunk_size = 3

for start in range(0, n, chunk_size):

end = min(start + chunk_size, n)

arr[start:end] = insertion_sort(arr[start:end])

arr = merge_sort(arr)

print(" ".join(map(str, arr)))

You might also like