CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:cylaps
Submission time:2023-11-09 00:45:55 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:11:26: error: cast from 'FILE*' to 'int' loses precision [-fpermissive]
   11 |   unsigned long l = read((int)stdin, s, 20);
      |                          ^
input/code.cpp:24:9: error: cast from 'FILE*' to 'int' loses precision [-fpermissive]
   24 |   write((int)stdout, s, l);
      |         ^
input/code.cpp:24:8: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   write((int)stdout, s, l);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~

Code

#include <stdio.h>
#include <unistd.h>
#include <string.h>

typedef unsigned char u1;

int main() {

  u1 s[500000];

  unsigned long l = read((int)stdin, s, 20);

  for (u1 *c = s; *c != '\n';) {
    if (*c - (u1)'0' < 9) {
      unsigned long n = *c - '0';
      memmove(c + n, c + 1, l - (unsigned long)(c - s) - 1);
      memcpy(c, c + n, n);
      l += n;
    } else {
      c++;
    }
  }

  write((int)stdout, s, l);

  return 0;
}