Development and debugging of algorithms and programs for processing character strings.

Given a string of characters consisting of letters of the English alphabet and spaces. Write a program that counts how many times each letter of the alphabet appears in a line.

Development and debugging of algorithms and programs using data structures.

The administrator of railway ticket offices has information about available seats in trains for the current day in the following form: destination, departure time, number of empty seats. Display information on the number of available seats on trains traveling to a given destination.

Array processing.

Given a square integer matrix F [m] [m]. Find the sums of the elements of those lines that have even elements on the main diagonal.

  • On the issue of strings - register to consider? - skegg
  • The elements of the main diagonal are those a [i] [j] for which i and j are equal. Parity check: if ((a [i] [i] & 1) == 0) {s + = a [i] [i]; } The cycle, I hope, you draw it yourself. At the same time look in what form the whole is represented in the car. It becomes clear why (a [i] [i] & 1) == 0. - avp

2 answers 2

Given that the largest code for the letter 'z' you can place an array of counters of the desired size:

int size = 'z'+1, i, lcnt[size]; 

Check that the character is a letter of the Latin alphabet:

 #include <ctype.h> ... char *s = ....; ... if (isalpha(s[i]) { lcnt[s[i]]++; // буква латинского алфавита } 

We print the result

 for (i = 'A'; i < size; i++) { // распечатаем счетчики if (isalpha(i)) printf ("letter %c %d times\n",i,lcnt[i]); } 

Notice how the int and char types are used in this case.

  • and this turbo si will not understand. array size cannot be variable - renegator
  • Then (if the pipe does not understand it) it is easy to write int lcnt ['z' + 1]; It will definitely understand. - avp
 #include<iostream> #include<map> using namespace std; int main(){ string s; cin.getline(s); map <char, int> ss; for(int i = 0; i <= s.size(); i++){ if(s[i]!=' ') ss[s[i]]++; } .. 
  • turbo si will not understand this - renegator
  • Yeah. What patterns, if - C - skegg