娄山中学noip吧 关注:137贴子:1,769
  • 14回复贴,共1

20120502作业

只看楼主收藏回复

单词查找
输入一个英文句子,例如:"This is a Book",可以看到英文句子是以"."来作为结束符号的,并且单词之间以一个空格来分隔。接着再输入一个单词,请找出首次在句子中出现的与该单词相同的单词,显示是句子中的第几个单词,若不存在,则输出该句子中单词字符的总个数。
例如:对上面的句子而言,若输入单词"is",则应输出:2; 若输入单词为"is a",则应输出:11。


1楼2012-05-02 16:16回复
    var
    s,s1 : string;
    i,j,k,t,l,p,q,n : longint;
    b : boolean;
    a : array[1..100] of string;
    begin
    while not eof do begin
    readln(s);
    readln(s1);
    t :=0;b :=true;
    for i :=1 to length(s1) do
    if s1[i]=' ' then begin
    for j :=1 to length(s) do if (s[j] in ['A'..'Z']) or (s[j] in ['a'..'z']) then inc(t);
    writeln(t);
    b :=false;
    break;
    end;
    if b then begin
    k :=0;j :=1;s[length(s)] :=' ';
    b :=false;
    for i :=1 to length(s) do
    if s[i]=' ' then begin
    k :=k+1;
    a[k] :=copy(s,j,i-j);
    j :=i+1;
    end;
    if a[1][1]<>s[1] then begin
    a[1] :=s;
    k :=1;
    end;
    for i :=1 to k do if a[i]=s1 then begin
    writeln(i);
    b :=true;
    break;
    end;
    if not b then begin
    t :=0;
    for j :=1 to length(s) do if (s[j] in ['A'..'Z']) or (s[j] in ['a'..'z']) then inc(t);
    writeln(t);
    end;
    end;
    end
    end.


    2楼2012-05-02 16:17
    回复
      1\(bt版)var
      s,w:string;
      a:array[1..100] of string;
      i,j,p,q:byte;
      su:word;
      b:boolean;
      begin
      while not eof do begin
      readln(s);
      q:=0;
      i:=0;
      fillchar(a,sizeof(a),' ');
      while i<=length(s) do begin
      inc(i);
      if (s[i] in ['a'..'z']) or (s[i] in ['A'..'Z']) then begin
      p:=i;
      j:=1;
      inc(q);
      while (s[p] in ['a'..'z']) or (s[p] in ['A'..'Z']) do begin
      a[q][j]:=s[p];
      inc(j);
      inc(p);
      end;
      i:=p-1;
      end;
      end;
      readln(w);
      for i:=length(w) to 31 do w:=w+' ';
      b:=false;
      su:=0;
      for i:=1 to q do if w=a[i] then begin writeln(i); b:=true; break; end;
      if b=false then begin
      for i:=1 to q do
      for j:=1 to length(a[i]) do if a[i][j]=' ' then break
      else inc(su);
      writeln(su);
      end;
      end;
      end.


      IP属地:美国3楼2012-05-02 16:17
      回复
        2、var
        s,w:string;
        a:array[1..100] of string;
        i,j,p,q,ss:byte;
        su:word;
        b:boolean;
        begin
        while not eof do begin
        readln(s);
        q:=0;
        i:=0;
        while i<=length(s) do begin
        inc(i);
        if (s[i] in ['a'..'z']) or (s[i] in ['A'..'Z']) then begin
        p:=i;
        j:=1;
        ss:=0;
        inc(q);
        while (s[p] in ['a'..'z']) or (s[p] in ['A'..'Z']) do begin
        inc(ss);
        inc(j);
        inc(p);
        end;
        a[q]:=copy(s,i,ss);
        i:=p-1;
        end;
        end;
        readln(w);
        b:=false;
        su:=0;
        for i:=1 to q do if w=a[i] then begin writeln(i); b:=true; break; end;
        if b=false then begin
        for i:=1 to q do su:=su+length(a[i]);
        writeln(su);
        end;
        end;
        end.
        


        IP属地:美国4楼2012-05-02 16:17
        回复


          5楼2012-05-02 17:54
          回复


            6楼2012-05-02 17:55
            回复


              7楼2012-05-02 17:56
              回复
                #include<iostream>
                #include<string>
                using namespace std;
                main (){
                char a[1000],b[1000];
                int length1=0,length2=0;
                do
                {
                length1++;
                scanf("%c",&a[length1]);
                }while (a[length1]!='\n');
                do
                {
                length2++;
                scanf("%c",&b[length2]);
                }while (b[length2]!='\n');
                a[0]=' ';
                int i,num=1,g=1;
                length1--;
                a[length1]=' ';
                length1--;length2--;
                for (i=1;i<=length1;i++){
                if (g==length2 && a[i-length2]==' ' && a[i+1]==' ') {
                if (num>0) cout<<num;
                num=-1000;
                }
                if (a[i]==' ') num++;
                else if (a[i]==b[g] || char(int(a[i])+32)==b[g] || char(int(a[i])-32)==b[g]) g++;
                else g=1;
                }
                if (num>=0) cout<<length1-num+1;
                system("pause");
                return 0;
                }


                8楼2012-05-02 19:56
                回复
                  1】:
                  const
                  a='0123456789ABCDEF';
                  var
                  s:string;
                  k,i,n,r:integer;
                  begin
                  readln(n);
                  k:=0;
                  while n>0 do begin
                  k:=k+1;
                  r:=n mod 16;
                  n:=n div 16;
                  insert(copy(a,r+1,1),s,k);
                  end;
                  for i:=length(s) downto 1 do write(s[i]);
                  readln;
                  end.
                  2】:
                  var
                  a,i,j,k:byte;
                  s:string;
                  min,b1,b2,b3:real;
                  begin
                  readln(s);
                  min:=3;
                  a:=length(s)-1;
                  for i:=1 to a do if s[i]<>'0' then k:=k+1;
                  if k<3 then write('ERROR')
                  else begin
                  for i:=1 to a-2 do
                  for j:=i+1 to a-1 do
                  begin
                  val(copy(s,1,i),b1);
                  val(copy(s,i+1,j-i),b2);
                  val(copy(s,j+1,a-j),b3);
                  if 1/b1+1/b2+1/b3<min then min:=1/b1+1/b2+1/b3
                  end;
                  end; write(min:0:6);
                  readln;
                  end.
                  


                  9楼2012-05-02 20:54
                  回复
                    完全正确,虽然交的不是这次的


                    10楼2012-05-03 17:24
                    回复
                      。。。


                      11楼2012-05-03 18:12
                      回复
                        var
                        s,b:string;
                        mad:array[1..10] of integer;
                        i,j,f:integer;
                        begin
                        readln(s);
                        delete(s,length(s),1);
                        mad[1]:=1;
                        j:=2;
                        for i:=1 to length(s) do if s[i]=' ' then begin mad[j]:=i+1;j:=j+1;end;
                        readln(b);
                        insert(' ',b,length(b)+1);
                        f:=pos(b,s);
                        for i:=1 to length(b)-1 do if b[i]=' ' then f:=0;
                        if f=0 then write(length(s)-j+1)
                        else for i:=1 to j-1 do if f=mad[i] then write(i);
                        readln;
                        end.
                        [要不要大小写啊


                        IP属地:上海12楼2012-05-06 10:02
                        回复
                          自己测试一下老师给的数据


                          13楼2012-05-06 13:50
                          回复
                            为什么有的时候可以有的时候不行。。。


                            IP属地:上海14楼2012-05-06 15:23
                            回复
                              你自己改咯


                              15楼2012-05-10 22:22
                              回复