Answer the question
In order to leave comments, you need to log in
Yandex Contest how to get rid of Memory Limit/Time Limit error?
There is the following task: yandex contest
There are 2 solutions:
//Решение 1:
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('input.txt'),
terminal: false
});
let prev;
rl.once('line', () => {
rl.on('line', line => {
if (line != prev) fs.appendFileSync('output.txt', `${prev ? '\n' : ''}${prev = line}`);
});
});
//Решение 2:
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('input.txt'),
terminal: false
});
let prev;
rl.once('line', () => {
rl.on('line', line => {
if (line != prev) process.stdout.write(`${prev ? '\n' : ''}${prev = line}`);
});
});
Answer the question
In order to leave comments, you need to log in
Pseudocode
открыл файл
a = прочитал одно число
пока файл не кончился
b = прочитал одно число
если a < b
вывел a
a = b
вывел a
the solution actually boils down to just removing duplicates from the input array
using System;
using System.Linq;
namespace Test {
class Program {
static void Main() {
int n = Convert.ToInt32(Console.ReadLine());
int i = 0;
int[]mass = new int[n];
while (n > 0) {
mass[i] = Convert.ToInt32(Console.ReadLine());
n--; i++;
}
mass = mass.Distinct().ToArray();
GC.SuppressFinalize(n); GC.SuppressFinalize(i);
GC.Collect();
foreach (var item in mass) {
Console WriteLine(item);
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question