Skip to content

Instantly share code, notes, and snippets.

View MahraibFatima's full-sized avatar
:fishsticks:
striving

Mahraib Fatima MahraibFatima

:fishsticks:
striving
View GitHub Profile
@MahraibFatima
MahraibFatima / Largest_odd_string.cpp
Created February 5, 2025 14:25
Largest Odd Number in String
#include <iostream>
#include <string>
using namespace std;
// Brute Force
string largestOddNumber(string number) {
int save = -1;
for(int i=number.size()-1; i>=0; --i){
// string ch = ;
int n = number[i] - '0';
@MahraibFatima
MahraibFatima / reverse_words_in_string.cpp
Created February 5, 2025 12:47
without extra multiple space between two words.
#include <iostream>
#include <string>
#include <stack>
#include <tuple>
using namespace std;
string reverseWords(string sentence) {
stack<string> words_stack;
string word = "";
for(int i=0; i<sentence.size(); ++i){
if(sentence[i] == ' ' && word != ""){
int reverseNum(int num){
int reversed_number=0;
while(num != 0) {
int remainder = num % 10;
reversed_number = reversed_number * 10 + remainder;
num /= 10;
}
return reversed_number;

Problem Statement

This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.

To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?


Input: The first and only line contains positive integers n, k, l, c, d, p, nl, np, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.

@MahraibFatima
MahraibFatima / isValidBridge.cpp
Created December 24, 2024 17:47
Safe examples: "#####", "## ####", "# ##", "### #", " ####" Unsafe examples: "# # ###", " # ##", " ## ## ", "# #### #"
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
bool isValidBridge( string s) {
char pre = '#';
int gap_cnt= 0, curr_gap= 0;
for(int i= 0; i<s.length(); ++i) {
if(s[i] == ' ') curr_gap++;
if(pre != s[i] && s[i] == ' ') gap_cnt++;
@MahraibFatima
MahraibFatima / isAnagram.py
Created March 19, 2024 16:18
Determine whether the entered strings are anagrams or not.
def is_anagram(s1, s2):
return sorted(s1) == sorted(s2)
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
if is_anagram(string1, string2):
print("Anagrams")
else:
print("Not anagrams")
@MahraibFatima
MahraibFatima / FindLCM.py
Last active March 19, 2024 16:16
Compute the least common multiple of the two input numbers.
def compute_lcm(x, y):
if x > y:
greater = x
else:
greater = y
while True:
if greater % x == 0 and greater % y == 0:
lcm = greater
break
@MahraibFatima
MahraibFatima / countVowels.py
Created March 19, 2024 16:14
Count the number of vowels in the input string.
def count_vowels(s):
vowels = 'aeiouAEIOU'
count = 0
for char in s:
if char in vowels:
count += 1
return count
@MahraibFatima
MahraibFatima / isLeapYear.py
Created March 19, 2024 16:12
Determine whether the entered year is a leap year or not .
def is_leap_year(year):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return True
return False
year = int(input("Enter a year: "))
if is_leap_year(year):
print("Leap year")
else:
print("Not a leap year")
@MahraibFatima
MahraibFatima / temperatureConvertor.py
Created March 19, 2024 16:10
Convert the temperature from Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)