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 / showSalaries.java
Created May 31, 2025 05:28
showSalaries method
public static void showSalaries(Connection conn, String dept) {
String sql = "SELECT name, salary FROM employees WHERE department = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, dept);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
double salary = rs.getDouble("salary");
System.out.println(name + " - " + salary);
}
@MahraibFatima
MahraibFatima / main.java
Created May 31, 2025 02:43
basic with swing and java visual programming
//Step 1: import lib
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
//step 2: Top level Frame / window
JFrame frame= new JFrame();
//step 3: container to frame
@MahraibFatima
MahraibFatima / Eid_Cringe_Msg.cpp
Created April 1, 2025 18:51
Your task is to determine which message is the most cringeworthy by computing its "cringe score" as follows: Each vowel (a, e, i, o, u — in any case) adds 1 point. Each standalone occurrence of the word "Eid" adds a bonus of 3 points. The message with the highest cringe score wins the championship. If there’s a tie, pick the one that appears fir…
// Example program
#include <iostream>
#include<vector>
#include <string>
using namespace std;
int main()
{
int no_of_eid_messages=0;
cout<<"Enter number of eid messages: ";
@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