帕斯卡将线分割为实数和字符串

发布于 2024-12-18 02:02:06 字数 562 浏览 1 评论 0原文

我知道这种语言几年前就已经消失了,但我们国家的大多数学校仍然需要 -.- 我得到了包含数据的文件,如下所示:

  • 行数 姓名
  • 姓氏(真实类型数字)(另一个真实类型数字)

例如

  • 2
  • Brat Sunbather 5.66 55.4
  • Bart Simpson 55.7 45.4

我需要创建结果文件,如下所示:

  • 姓名(之前给出的真实数字相乘)
  • 总计

例如

  • Brat Sunbather 313.56
  • Bart Simpson 2528.78
  • 总计:2842.34

我一直试图将行拆分为字符串和实数,即使在我在示例中给出的书中,所有数据都在单独的行上:

  • String
  • Digit
  • String
  • Digit

我在网上找不到任何内容希望你能帮助我。先感谢您。

I know that this language have died a couple of years ago, but still required in most of schools in our country -.-
I got file with data, which looks like:

  • Number of lines
  • Name Surname (real type digit) (another real type digit)

For e.g.

  • 2
  • Brat Sunbather 5.66 55.4
  • Bart Simpson 55.7 45.4

And I need to create result file, which looks like this:

  • Name Surname (Previously given real type digits multiplied)
  • Total

For e.g.

  • Brat Sunbather 313.56
  • Bart Simpson 2528.78
  • Total: 2842.34

I'm stuck in trying to split the line into string and real, even in the book I've given in the examples all data is on separate line:

  • String
  • Digit
  • String
  • Digit

I can't find anything on the net and hope you could help me. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2024-12-25 02:02:06

这应该可以帮助您开始 - 我已经阅读了文件,分割了行,并将字符串转换为实数:

Program Test;

var
    fileVar: Text;
    l: string[81];
    inputFilename: string[14];
    lCount: Integer;
    i: Integer;
    code: Integer;

    spacePos: Integer;

    firstName: string[100];
    secondName: string[100];

    num1: real;
    num2: real;
    product: real;

    s: string[100];

begin
    inputFilename := 'input.txt';
    Assign(fileVar, inputFilename);
    Reset(fileVar);

    Readln(fileVar, l);
    Val(l, lCount);

    Writeln('l count=', lCount);

    for i := 1 to lCount do
    begin
        Readln(fileVar, l);
        spacePos := Pos(' ', l);
        firstName := Copy(l, 0, spacePos);
        Delete(l, 1, spacePos);

        spacePos := Pos(' ', l);
        secondName := Copy(l, 0, spacePos);
        Delete(l, 1, spacePos);

        spacePos := Pos(' ', l);
        s := Copy(l, 0, spacePos - 1);
        Val(s, num1, code);
        Delete(l, 1, spacePos);

        Val(l, num2, code);

        WriteLn(firstName);
        Writeln(secondName);
        Writeln(num1);
        Writeln(num2);
    end;

    Close(fileVar);
end.


This should get you started - I got as far as reading the file, splitting the line, and converting the strings to reals:

Program Test;

var
    fileVar: Text;
    l: string[81];
    inputFilename: string[14];
    lCount: Integer;
    i: Integer;
    code: Integer;

    spacePos: Integer;

    firstName: string[100];
    secondName: string[100];

    num1: real;
    num2: real;
    product: real;

    s: string[100];

begin
    inputFilename := 'input.txt';
    Assign(fileVar, inputFilename);
    Reset(fileVar);

    Readln(fileVar, l);
    Val(l, lCount);

    Writeln('l count=', lCount);

    for i := 1 to lCount do
    begin
        Readln(fileVar, l);
        spacePos := Pos(' ', l);
        firstName := Copy(l, 0, spacePos);
        Delete(l, 1, spacePos);

        spacePos := Pos(' ', l);
        secondName := Copy(l, 0, spacePos);
        Delete(l, 1, spacePos);

        spacePos := Pos(' ', l);
        s := Copy(l, 0, spacePos - 1);
        Val(s, num1, code);
        Delete(l, 1, spacePos);

        Val(l, num2, code);

        WriteLn(firstName);
        Writeln(secondName);
        Writeln(num1);
        Writeln(num2);
    end;

    Close(fileVar);
end.


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文