Permalink
Browse files

Freopen in different langs

  • Loading branch information...
watashi committed Jun 9, 2013
1 parent ba05581 commit 3d3d96dd0810156c64c7b95cdc1738920ccee90b
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
int main(void) {
int n, i;
static char s[1 << 20];
#ifndef __WATASHI__
freopen("positive.in", "r", stdin);
freopen("positive.out", "w", stdout);
#endif
scanf("%d ", &n);
fgets(s, sizeof(s), stdin);
for (i = 0; s[i] != '\0'; ++i) {
if (s[i] == '-') {
n -= 2;
}
}
if (n < 0) {
n = 0;
}
printf("%d\n", n);
return 0;
}
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
#ifndef __WATASHI__
struct $ {
$(const char* input, const char* output) {
freopen(input, "r", stdin);
freopen(output, "w", stdout);
}
} $("positive.in", "positive.out");
#endif
int main(void) {
int n;
static char s[1 << 20];
scanf("%d ", &n);
fgets(s, sizeof(s), stdin);
for (int i = 0; s[i] != '\0'; ++i) {
if (s[i] == '-') {
n -= 2;
}
}
if (n < 0) {
n = 0;
}
printf("%d\n", n);
return 0;
}
@@ -0,0 +1,36 @@
using System;
using System.IO;
public class F {
#if !__WATASHI__
class FakeConsole: StreamWriter {
StreamReader reader;
public FakeConsole(string input, string output): base(output) {
reader = new StreamReader(input);
AutoFlush = true;
}
public int Read() {
return reader.Read();
}
public string ReadLine() {
return reader.ReadLine();
}
}
static FakeConsole Console = new FakeConsole("positive.in", "positive.out");
#endif
public static void Main(String[] args) {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
foreach (char c in s) {
if (c == '-') {
n -= 2;
}
}
Console.WriteLine(Math.Max(n, 0));
}
}
@@ -0,0 +1,23 @@
import std.conv;
import std.stdio;
import std.process;
void main() {
if (getenv("USER") != "watashi") {
stdin = File("positive.in", "r");
stdout = File("positive.out", "w");
}
string s = readln();
int n = parse!int(s);
string t = readln();
foreach (c; t) {
if (c == '-') {
n -= 2;
}
}
if (n < 0) {
n = 0;
}
writefln("%d", n);
}
@@ -0,0 +1,16 @@
var
n, i, x: integer;
begin
{$IFNDEF __WATASHI__}
assign(input, 'positive.in');
assign(output, 'positive.out');
{$ENDIF}
readln(n);
for i := 1 to n do begin
read(x);
if x < 0 then dec(n, 2);
end;
if n < 0 then n := 0;
writeln(n);
end.
@@ -0,0 +1,29 @@
package main
import (
"fmt"
"os"
)
func main() {
if (os.Getenv("USER") != "watashi") {
os.Stdin, _ = os.Open("positive.in")
os.Stdout, _ = os.Create("positive.out")
}
var n, m int
fmt.Scanf("%d", &n)
fmt.Scanln()
m = n
for i := 0; i < n; i++ {
var x int
fmt.Scanf("%d", &x)
if x < 0 {
m -= 2
}
}
if m < 0 {
m = 0
}
fmt.Printf("%d\n", m)
}
@@ -0,0 +1,22 @@
{-# LANGUAGE CPP #-}
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as C
interact' :: (C.ByteString -> String) -> IO ()
#ifndef __WATASHI__
interact' = hInteract "positive.in" "positive.out"
hInteract :: FilePath -> FilePath -> (C.ByteString -> String) -> IO ()
hInteract input output f =
liftM f (C.readFile input) >>= writeFile output
#else
interact' = interact . (. C.pack)
#endif
main :: IO ()
main = interact' $ \input ->
let (n:a) = map readInt $ C.words $ input in
(++"\n") $ show $ max 0 $ (n-) $ (2*) $ length $ filter (<0) $ a
where
readInt = fst . fromJust . C.readInt
@@ -0,0 +1,39 @@
import java.io.*;
import java.util.*;
public class F {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String s = in.nextLine();
for (char c: s.toCharArray()) {
if (c == '-') {
n -= 2;
}
}
System.out.println(Math.max(n, 0));
}
}
final class System {
public static InputStream in = java.lang.System.in;
public static PrintStream out = java.lang.System.out;
public static PrintStream err = java.lang.System.err;
public static void exit(int status) {
java.lang.System.exit(status);
}
static {
if (java.lang.System.getProperty("ONLINE_JUDGE") != null) {
try {
String file = "positive";
in = new BufferedInputStream(new FileInputStream(file + ".in"));
out = new PrintStream(new FileOutputStream(file + ".out"));
} catch (IOException ex) {
}
}
}
}
@@ -0,0 +1,12 @@
let _ =
let fin = open_in "positive.in" in
let fout = open_out "positive.out" in
let n = int_of_string (input_line fin) in
let a = ref [] in
for i = 1 to n do
let x = Scanf.fscanf fin " %d" (fun x -> x) in
a := x :: !a
done;
let s = List.fold_left (fun x y -> x + y) 0 !a in
Printf.fprintf fout "%d\n" (max 0 s)
;;
@@ -0,0 +1,18 @@
var
n, i, x: integer;
begin
{$IFNDEF __WATASHI__}
assign(input, 'positive.in');
assign(output, 'positive.out');
reset(input);
rewrite(output);
{$ENDIF}
readln(n);
for i := 1 to n do begin
read(x);
if x < 0 then dec(n, 2);
end;
if n < 0 then n := 0;
writeln(n);
end.
@@ -0,0 +1,20 @@
<?php
if (getenv('USER') == 'watashi') {
$STDIN = STDIN;
} else {
$STDIN = fopen('positive.in', 'r');
$STDOUT = fopen('positive.out', 'w');
ob_start(function($buffer) {
global $STDOUT;
fwrite($STDOUT, $buffer);
});
}
$n = fgets($STDIN) + 0;
$a = fgets($STDIN);
foreach (explode(' ', $a) as $i) {
if ($i < 0) {
$n -= 2;
}
}
echo max($n, 0), "\n";
@@ -0,0 +1,17 @@
#!/usr/bin/perl
use strict;
use warnings;
INIT {
if ($ENV{'USER'} ne 'watashi') {
open STDIN, '<', 'positive.in';
open STDOUT, '>', 'positive.out';
}
}
my $n = <STDIN>;
my $s = <STDIN>;
$n -= 2 * ($s =~ y/-/-/);
$n = 0 if $n < 0;
print "$n\n";
@@ -0,0 +1,12 @@
#!/usr/bin/python2
import os, sys
if os.getenv('USER') != 'watashi':
sys.stdin = open('positive.in', 'r')
sys.stdout = open('positive.out', 'w')
if __name__ == '__main__':
n = input()
n -= 2 * raw_input().count('-')
print max(n, 0)
@@ -0,0 +1,12 @@
#!/usr/bin/python3
import os, sys
if os.getenv('USER') != 'watashi':
sys.stdin = open('positive.in', 'r')
sys.stdout = open('positive.out', 'w')
if __name__ == '__main__':
n = int(input())
n -= 2 * input().count('-')
print(max(n, 0))
@@ -0,0 +1,18 @@
import java.io._
import scala.math._
object F {
if (util.Properties.userName != "watashi") {
scala.Console.setIn(
new BufferedInputStream(new FileInputStream("positive.in")))
scala.Console.setOut(
new PrintStream(new FileOutputStream("positive.out")))
}
def main(args: Array[String]) {
val n = readLine().toInt
val a = readLine().split(" ").map(_.toInt)
println(max(0, a.sum))
}
}

0 comments on commit 3d3d96d

Please sign in to comment.