为什么程序不能正常工作? [英] Why doesn't the program work as it should be?

查看:82
本文介绍了为什么程序不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我必须制作此程序,但我还没有完成它,我需要一些帮助。这就是我必须要做的。在Pascal中创建一个程序,在读完带有nums列表的文本之后,它将返回麻木。在文本中出现不到一次的nums。



将从程序中读取的文本应该是这样的。



在第一行有两个nums。由空间分隔,n和m。 N是存在的nums的数量,如果文本包含数字1,2,3,4,n是4(1..n)。 M是多少行。每一行都有几个n,b,(1 = b)a和b用空格分隔。



该程序的文件将会写上一个数字,表示在文本中出现了少于两个时间的nyms。



所有的数字。是整数。



0 =



我做了以下程序,但它只读取了文本的第一行。谁可以帮助我?截止日期快要结束了。提前致谢。我的代码如下。





我之后制作了代码,该程序是如何将变量放入变量的所有nums中。我是初学者,所以如果有人能给我一个例子,会有很多帮助。

红色文本示例。

domes.in

6 7

2 4

4 1

3 5

4 3

1 3





Hello, i have to make this program, but i still haven't finished it and i need some help. This is what i have to do. Make a program in Pascal that after has read a text with a list of nums., it will return the numb. of the nums that appear less than one times in the text.

The text that will be read from the program should be like that.

In the first line there are two nums. seperated by a space, n and m. N is the number of nums that exist, like if the text contains the numbers 1,2,3,4, n is 4 (1..n). M is how many lines follow. Every line has a couple of nums, a,b, (1=
b) a and b are separated by a space.

The file that the program will make will have written on it a num., that says how many nyms are appeared less than two tims in the text.

All the nums. are Integer.

0=


i've made the following program, but it only reads the first line of the text. Anyone that can help me? The deadline is almost ended. Thanks in advance. My code is the following.


I've made the code after that, the program is how to put into variables all the nums. I'm a beginner so if anyone could give me an example, would help a lot.
Example of the text that reds.
domes.in
6 7
2 4
4 1
3 5
4 3
1 3


Program thefinalp;
  Uses SysUtils;
        
  Var
    f:Text;
    m,d:Integer;
    n:Char;
    c:String[1];
        
    a,e:array of integer;
    LowArr:Integer;
    HighArr:Integer;
    ArrayLen:Integer;
    i:Integer;
        
        
    begin
      Assign(f,'finalp.txt');
      Reset(f);
        
      repeat
        Read (f,n);
        Write(n);
      until (n=' ');
        
      Read(f,c);
      Write(c);
        
      readln(f,d);
      Writeln(d);
        
      StrToIntDef(n,m);
        
      setlength(a,m);
      LowArr:=Low(a);
      HighArr:=High(a);
      ArrayLen:=Length(a);
        
      setlen;
      LowArr:=Low(e);
      HighArr:=High(e);
      ArrayLen:=Length(e);
        
      for i:= LowArr to HighArr do
      begin
        repeat
          Read (f,a[i]);
          Write(a[i]);
        until (n=' ');
            
        Read(f,c);
        Write(c);

        readln(f,e[i]);
        Writeln(e[i]);
        
      End;

      Readln;
    End.





代码缩进添加 - OriginalGriff [/ edit]

[edit]修正了预标签 - Matt T Heffron [/ edit]

推荐答案

因为< a href =http://www.freepascal.org/docs-html/rtl/system/seekeoln.html> seekEoln [ ^ ]如果它在一行的末尾则返回true。这不是你第一次在 sth 程序中进入循环,但是在调用readln之后会立即...



请为自己帮个忙:学会缩进代码,使其至少部分可读?这将使你的生活在未来变得更加轻松,以及我们现在......:叹息:
Because seekEoln[^] returns true if it is at the end of a line. Which it won't be the first time you enter the loop in your sth procedure, but will be immediately after calling readln...

And please, do yourself a favor: learn to indent your code so it is at least partly readable? It'll make your life a lot easier in the future, as well as our now... :sigh:


这篇关于为什么程序不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆