Replace every letter with its adjacent letter and convert all vowels to uppercase.

C++ #include<iostream> using namespace std; bool isAlphabet(char c) { if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return true; return false; } bool isVowel(char c) { char vowels[] = {'a', 'e', 'i', 'o', 'u'}; for (char vowel : vowels) { if (vowel == c) { return true; … Continue reading Replace every letter with its adjacent letter and convert all vowels to uppercase.

Replace Words in a file and print count

JAVA import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; public class ReplaceWords { public static long countWords(String source, String wordToCount) { String[] words = source.split(" "); int count = 0; for (String word : words) { if (word.equals(wordToCount)) count++; } return count; } public static long replaceWords(String filePath , String[] wordsToReplace , String[] wordsToReplaceWith) throws … Continue reading Replace Words in a file and print count

[C#]Convert List/Enumerable to DataTable

public static DataTable ToDataTable<T>(this IEnumerable<T> iEnumerable) { if(iEnumerable is null) throw new ArgumentNullException(nameof(iEnumerable), "Enumerable is null"); var dataTable = new DataTable(); var propertyDescriptorCollection = TypeDescriptor.GetProperties(typeof(T)); foreach (PropertyDescriptor propertyDescriptor in propertyDescriptorCollection) { var type = propertyDescriptor.PropertyType; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) type = Nullable.GetUnderlyingType(type); dataTable.Columns.Add(propertyDescriptor.DisplayName, type!); } var values = new object[propertyDescriptorCollection.Count]; foreach (var iListItem … Continue reading [C#]Convert List/Enumerable to DataTable

Programming Notes

Multiple expressions in while LoopPost-Pre same effect in For loop (Use Pre in Loops)Any non-zero integer is considered false.Return value of printf() is numbers of character printed.Return value of Scanf() is number of values scanned.C and C++ does not throw (Array index out of Bound Exception).Comma operator has lowest precidence, comma executes first expression, executes … Continue reading Programming Notes

[Kotlin] Check if string is anagram

fun isAnagramSumCheck(string1: String, string2: String): Boolean { val cleanedString1 = cleanString(string1) val cleanedString2 = cleanString(string2) return if (cleanedString1.length != cleanedString2.length) false; else { cleanedString1.toLowerCase().sumBy { it.toInt() } == cleanedString2.toLowerCase().sumBy { it.toInt() } } } fun cleanString(string: String): String { return string.replace( Regex("[^a-zA-Z]"), "") } fun isAnagramCharCheck(string1: String, string2: String): Boolean { val cleanedString1 = cleanString(string1) … Continue reading [Kotlin] Check if string is anagram

[Programmers.Io] ‘CHOCX’ Cake Inventory

‘CHOCX’ is a bakery specialized in chocolate cakes. Their cake formula is - each cake contains 40% Bread, 10% Sugar, 30% Cream, 20% chocolate. They accept order via mail for X kg cake. In response, they confirm if they can deliver the cake with a “Thank you” or if they can’t with a “Sorry” note. When they respond they make sure, if any component is greater and equal to the required component, they retain 1 kg of each component Bread, Sugar, Cream, Chocolate in their inventory.

[Programmers.IO] minimum Assistance Problem

A finance company wants to hire some support assistance based upon their cases arrival and solved time but the company is confused with what is the minimum number of assistance required to handle the cases. Help the company to calculate minimum number to assistance can handle the cases. WAP to take input of 2 array/list (One for Case Arrival Time another of Case Solved Time), and your program should return the minimum number of assistance required for the company. Note: Assign assistance in such a way that no cases needed to be wait to arrive.