Grade 10 · 16 algorithmsCitește în română
Character stringsȘiruri de caractere
Every character strings algorithm from the Romanian high school curriculum, with the idea explained, its complexity, examples and code you can edit and run right here.
- 16algorithms
- 6chapters
- 1grade
16 algorithms
0%
Character strings
Șiruri de caractere · 16 algorithms
- The longest wordCel mai lung cuvântWe split the sentence into words with strtok and keep the longest word in a separate string, copying it with strcpy (we cannot write celMaiLung = p,…
- Caesar cipherCifrul lui CezarEvery letter is replaced by the letter k positions further in the alphabet, circularly (after 'z' comes 'a'). We turn the letter into its position…
- Palindrome words in a sentenceCuvintele palindrom dintr-o frazăWe combine two things learned before: strtok splits the sentence into words, and the function estePalindrom(p) checks a word with two indices moving…
- Removing the vowelsEliminarea vocalelorWe delete the vowels in the original string itself, with two indices: i reads every character, k shows where the next kept character is written.…
- Extracting the numbers from a textExtragerea numerelor dintr-un textWe walk the text; when we meet a digit, we build the number as in grade 9 (nr = nr * 10 + (s[i] - '0')) while digits follow. The expression s[i] -…
- Letter frequencyFrecvența literelorWe count how many times each letter appears, without distinguishing uppercase from lowercase: tolower(c) - 'a' gives the letter's position in the…
- Splitting into words with strtokÎmpărțirea în cuvinte cu strtokstrtok(s, separators) returns the first word of s; the following calls are made with NULL instead of s and return the other words one by one, until…
- Replacing one word with anotherÎnlocuirea unui cuvânt cu altulA text and two words, old and new, are read (each on its own line). We build the result in a new string: spaces are copied as they are, and every…
- Converting to uppercase and lowercaseTransformarea în majuscule și minusculeIn the ASCII table the uppercase letters 'A'..'Z' and the lowercase 'a'..'z' are a constant distance apart: 'a' - 'A' = 32. A lowercase letter…
- Counting the wordsNumărarea cuvintelorWithout strtok: a word starts where a non-space character follows a space (or sits at the very beginning of the string). We count these…
- Counting the vowelsNumărarea vocalelorFor every character we check whether it appears in the string "aeiouAEIOU" with the function strchr: strchr(vowels, c) returns the address of the…
- Operations with std::stringOperații cu std::stringThe string class from <string> manages its own memory: it is assigned with =, concatenated with +, compared with == and <. getline(cin, s) reads the…
- Walking a string and its lengthParcurgerea unui șir și lungimea luiA C-style string is a char array terminated by the null character '\0'. cin.getline(s, 256) reads the whole line, spaces included (cin >> s would…
- Sorting words alphabeticallySortarea alfabetică a cuvintelorWe split the sentence into words with strtok and copy them into a character matrix cuv[100][31] (every row is a string). We sort with bubble sort;…
- Checking a palindrome stringVerificarea unui șir palindromFirst we keep only the letters, turned into lowercase (so 'Ele fac cafele' becomes 'elefaccafele'). Then we use two indices: st starts at the…
- Checking anagramsVerificarea anagramelorTwo words are anagrams if they have the same letters, the same number of times, in a different order (for example 'roma' and 'amor'). We use a…