Pascal/Turbo Pascal - Problema con manejo de caracteres

 
Vista:
sin imagen de perfil

Problema con manejo de caracteres

Publicado por Antonio (12 intervenciones) el 13/05/2013 06:09:00
Hola.
Tengo un problema que dice:

Se lee una secuencia de caracteres terminada en ‘*’. La secuencia se divide en palabras. Contar la
cantidad de palabras de al menos seis caracteres que empiezan y terminan con ‘s’, y en tienen
exactamente dos ‘e’.
Ejemplo: sociedades sextos socio series *  cantidad = 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
program p3e3;
var
   cant,caracteres,e:integer;
   car,ant:char;
begin
     ant:=' ';
     cant:=0;
     read(car);
 
     while (car<>'.') do
     begin
          caracteres:=caracteres+1;
          if (car='s')and(ant=' ') then
          begin
               while (car<>' ') do
               begin
                    if (car='e') then
                       e:=e+1;
                    ant:=car;
                    read(car);
                    caracteres:=caracteres+1;
               end;
               if (ant='s')and(caracteres>=6)and(e=2) then
                  cant:=cant+1;
          end;
          ant:=car;
          read(car);
     end;
 
     writeln('Cantidad de palabras: ',cant);
     readln;
end.


no me funciona. no parece recorrer toda la palabra.Que puede ser?
Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Problema con manejo de caracteres

Publicado por ramon (2158 intervenciones) el 22/05/2013 13:41:12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{A ver si esto ayuda}
 
 program caracteres;
 uses
    crt;
 const
    fin : char = '.';
 var
   linea : string;
   cont, i : integer;
   palabras, conm, ters, cmcs : integer;
   caract : char;
 
 
  procedure entradatexto;
  var
    blanco : boolean;
    t : integer;
  begin
     blanco := false;
     ters := 0;
     conm := 0;
     cmcs := 0;
     palabras := 0;
     writeln('**** Entre la linea de texto terminada en [.] ****');
     caract := ' ';
     cont := 1;
     writeln;
   while (caract <> '.') and (cont < 255) do
   begin
       caract := readkey;
       if caract <> #13 then
       begin
       write(caract);
       end
     else
       begin
          writeln;
       end;
       if caract = '.' then
       begin
          linea[cont] := ' ';
          linea[0] := chr(cont);
          cont := cont + 1;
       end;
       linea[cont] := caract;
       linea[0] := chr(cont);
       cont := cont + 1;
   end;
      for i := 1 to length(linea) do
      begin
          if linea[i] = ' ' then
          begin
             blanco := true;
          end;
        if (linea[i] in['s','S']) and (linea[i + 1] = ' ') then
        begin
            ters := ters + 1;
        end;
        if (linea[i] = ' ') and (linea[i + 1] in['m','M']) then
        begin
           conm := conm + 1;
        end;
        if linea[i] in['m','M'] then
        begin
           t := i;
         repeat
           if linea[t + 1] = ' ' then
           begin
              if (linea[t] in['s','S']) and (linea[i] in['m','M']) then
              cmcs := cmcs + 1;
           end;
           t := t + 1;
         until (linea[t] = ' ') or (t > length(linea));
        end;
          if (linea[i] = ' ') and (linea[i + 1] <> ' ') then
          begin
              palabras := palabras + 1;
          end;
      end;
  end;
 
  begin
      clrscr;
      entradatexto;
      writeln;
      writeln(' Tiene ',palabras,' Palabres');
      writeln(' Tiene ',ters,' Terminadas en [S]');
      writeln(' Tiene ',conm,' Comenzando en [M]');
      writeln(' Tiene ',cmcs,' Empiezan por [M] y terminan por [S]');
      writeln;
      writeln('   Pulse [Enter]');
      readln;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar