切换到宽版
  • 6896阅读
  • 4回复

『求助』哎~~~~~~~~ [复制链接]

上一主题 下一主题
离线little影
 
只看楼主 倒序阅读 0 发表于: 2005-11-22
郁闷啊
好不容易进了复赛
而且……
第一题编的差不多了的
就是“学生名字的读入”没搞定
结果省2等奖泡汤了
(米是四川的,有一道题做出来就2等的,才学两月,满足了)
~~~~~~~
谁能告诉我
那“名字”(字符串)怎么读
拜托拉!
THANK YOU!



下面是我的源程序
各位老鸟大哥们帮个忙哈






program scholar;
var
  n{学生人数}:integer;
  ch1{是否干部},ch2{是否西部的},chk{空格}:char;
  ch:array[1..20] of char;
  a{班末平均成绩},b{班级评议},c{论文数},i,l,j,k:longint;
  stu{学生名字}:array[1..100]of string[20];
  money:array[1..100]of integer;
  total1{名字占的字符数},total2{钱总数}:integer;
  f1.f2:text;
begin

assign(f1,'scholar.in');
reset(f1);

readln(f1,n);

  for i:=1 to n do

  begin

        total1:=0;
        repeat
          begin
            read(f1,ch[l]);
            total1:=total1+1;
          end
        until ch[l]=' ';

        stu:='';
          for l:=1 to total1 do
            stu:=stu+ch[l]);

       


        read(f1,a,b,chk,ch1,chk,ch2,c);
        readln(f1);

        { 读数据部分 }


              money:=0;
              if (a>80) and (a<=100) and (c>=1) and (c<=10)
              then money:=money+8000;
              if (a>85) and (a<=100) and (b>80) and (b<=100)
              then money:=money+4000;
              if (a>90) and (a<=100)
              then money:=money+2000;
              if (a>85) and (a<=100) and (ch2='Y')
              then money:=money+1000;
              if (b>80) and (b<=100) and (ch1='Y')
              then money:=money+850;

        { 算钱 }


  end;
  close(f1);



            total2:=0;
                for i:=1 to n do total2:=total2+money;

        {算总钱}

            for i:=1 to (n-1) do
              for j:=i+1 to n do
                if money<money[j] then
                      begin
                        k:=money;
                        money:=money[j];
                        money[j]:=k;
                      end;


        {从高到底排序}


        assign(f2,'scholar.out');
        rewrite(f2);


        writeln(f2,stu[1]);
        writeln(f2,money[1]);
        writeln(f2,total2);


        close(f2);
end.










[ 此贴被little影在2005-12-06 18:58重新编辑 ]
离线tctc
只看该作者 1 发表于: 2005-11-22
我用WHILE语句,一个个字符读入,在把读入的字符加到原来已读的字符串上,读到空格为止.或者一行行读,然后用COPY和WHILE截取空格前的字符串.暂时只想到那么多…………

p.s其他地方不是有分就可以有二等的吗?(去年第一道是很明显的送分不算…………)
离线stevenjl

只看该作者 2 发表于: 2005-11-25
一行行读不好
你后面数字的读入就麻烦了

所以还是用char

这道变态的题目主要就是阴险在integer的溢出问题
Dream Walker...
离线little影
只看该作者 3 发表于: 2005-12-06
integer溢出?
用longint不就可以了吗?
离线pzy
只看该作者 4 发表于: 2005-12-19
PASCAL语言

这是我的程序
const
  inf='scholar.in';
  outf='scholar.out';
type
  studentdata=record {定义记录类型}
    name:string;
    schoolscore,classscore,article:integer;
    ganbu,western:boolean;
    s0:longint;
  end;
var
  n,i,m:integer;
  stu:array [1..100] of studentdata;
  s,max:longint;
  ch:char;
begin
  assign(input,inf);
  reset(input);
  assign(output,outf);
  rewrite(output);
  readln(n);
  s:=0;
  max:=0;
  for i:=1 to n do
    with stu do {开域语句}
      begin
        read(ch);
        name:='';
        while ch<>' ' do
          begin
            name:=name+ch;
            read(ch);
          end;
        read(schoolscore,classscore);
        read(ch);
        read(ch);
        case ch of
          'Y': ganbu:=true;
          'N': ganbu:=false;
        end;
        read(ch);
        read(ch);
        case ch of
          'Y': western:=true;
          'N': western:=false;
        end;
        readln(article);
        s0:=0;
        if ((schoolscore>80) and (article>=1)) then
          inc(s0,8000);
        if ((schoolscore>85) and (classscore>80)) then
          inc(s0,4000);
        if schoolscore>90 then
          inc(s0,2000);
        if ((western) and (schoolscore>85)) then
          inc(s0,1000);
        if ((ganbu) and (classscore>80)) then
          inc(s0,850);
        inc(s,s0);
        if s0>max then
          begin
            max:=s0;
            m:=i;
          end;
      end;
  writeln(stu[m].name);
  writeln(max);
  writeln(s);
  close(input);
  close(output);
end.

绝对能行 我是普及组的都做起了
快速回复
限100 字节
 
上一个 下一个