Write a loop that reads strings from standard input where the string is either "land", "air", or "water". the loop terminates when "xxxxx" (five x characters) is read in. other strings are ignored. after the loop, your code should print out 3 lines: the first consisting of the string "land:" followed by the number of "land" strings read in, the second consisting of the string "air:" followed by the number of "air" strings read in, and the third consisting of the string "water:" followed by the number of "water" strings read in. each of these should be printed on a separate line. assume the availability of a variable, stdin, that references a scanner object associated with standard input.

Respuesta :

var
    land, air, water, x: integer;
    temp: string;
begin
   land := 0;
   air := 0
   water := 0;
   x := 0;

   //an infinite loop broken by 'xxxxx'
   while (true) do 
   begin
      temp = copy(stdin, x, 5); 
      if temp = ''xxxxx' then
          break;
      if copy(temp, 1, 3) = 'air' then
      begin
          air := air + 1;
          continue;
      end;
      if copy(temp, 1, 4) = 'land' then
      begin
          land := land + 1;
          continue;
      end;
      temp = 'water' then
      begin
          water := water + 1;
          continue;
      end;
      x := x + 1; 
   end;
   printline('air ' + IntToStr(air));

   printline('water ' + IntToStr(water));

   printline('land ' + IntToStr(land));
   


end;