A - Your First Judge Editorial by en_translator


Receive the input to the program as a string \(S\), and check if \(S\) is equal to Hello,World!. There are two key points.

Receiving an input / outputting the answer

It entirely depends on what programming language you use how to receive the input as a string or to output the answer. In some programming language, that may have some difficulties.
In order to figure out the usage of standard input output, we can:

  • refer to the documents or articles about the language.
  • refer to the submissions for the past contest in that language.
Comparing strings

The way to compare strings greatly varies with programming languages too. Some languages have slightly different definitions of string comparison operator from others. Some languages do not even have the string type.
However, most languages come with some ways of comparing strings, so it is essential to understand how to use them.

Sample codes with various languages follow.
Note that the code for some languages cannot be copy-and-pasted via the copy button.

C

#include<stdio.h>

int main(){
  char s[32];
  scanf("%s",s);
  if(strcmp(s,"Hello,World!")==0){printf("AC\n");}
  else{printf("WA\n");}
  return 0;
}

C++

#include<bits/stdc++.h>

using namespace std;

int main(){
  string s;
  cin >> s;
  if(s=="Hello,World!"){cout << "AC\n";}
  else{cout << "WA\n";}
  return 0;
}

Java

import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String ac = new String("Hello,World!");
    if(s.equals(ac)){System.out.println("AC");}
    else{System.out.println("WA");}
  }
}

Python

s = input()

if (s=="Hello,World!"):
  print("AC")
else:
  print("WA")

Bash

#!/bin/bash

read -r s

if [ $s = "Hello,World!" ]; then
    echo AC
else
    echo WA
fi

Awk

{print $1=="Hello,World!"?"AC":"WA"}

C#

using System;
class Program{
  static void Main(string[] args){
    string s = Console.ReadLine();
    string ac = "Hello,World!";
    if(s.Equals(ac)){Console.WriteLine("AC");}
    else{Console.WriteLine("WA");}
  }
}

Clojure

(println (if (= (read-line) "Hello,World!") "AC" "WA"))

Crystal

s = read_line
puts s=="Hello,World!" ? "AC" : "WA"

D

import std.stdio;
import std.string;
import std.conv;
void main(){
  string s=chomp(readln());
  writefln("%s",s=="Hello,World!"?"AC":"WA");
}

Dart

import 'dart:io';

main(List<String> args) {
  String s = stdin.readLineSync();
  if(s=="Hello,World!"){print("AC");}
  else{print("WA");}
}

Erlang

-module('Main').
-export([main/1]).

calc("Hello,World!") -> true;
calc(_) -> false.

solve() ->
  [S] = input("~s"),
  io:format("~s~n", [case calc(S) of true -> "AC"; false-> "WA" end]),
  ok.

main(_) ->
  solve(),
  halt().

input(Pat) ->
  {ok, L} = io:fread("", Pat),
  L.

Elixir

defmodule Main do
  def main do
    s = IO.read(:line) |> String.trim
    if (s == "Hello,World!"), do: IO.puts("AC"), else: IO.puts("WA")
  end
end

F#

open System

let s = stdin.ReadLine()
if (s = "Hello,World!") then "AC" else "WA"
|> printfn "%s"

Fortran

program abc215a

implicit none

character(32)::s
read(*, "(a)") s

if(s=="Hello,World!") then
  print"(a)","AC"
else
  print"(a)","WA"
end if

end program abc215a

Go

package main

import "fmt"

func main() {
  var s string
  fmt.Scan(&s)
  if(s=="Hello,World!"){
    fmt.Println("AC")
  }else{
    fmt.Println("WA")
  }
}

Haskell

import Control.Applicative

main :: IO ()
main = do
  s <- getLine
  putStrLn $ if s=="Hello,World!" then "AC" else "WA"

Haxe

import haxe.io.Input;

class Main {
  static function main() {
    var input : Input = Sys.stdin();
    var s = input.readLine();
    if(s=="Hello,World!") Sys.print("AC") else Sys.print("WA");
  }
}

JavaScript

function main(input) {
  const S = input.split('\n')[0];
  if(S == 'Hello,World!'){
    console.log('AC');
  }else{
      console.log('WA');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Julia

s = readline()
if s=="Hello,World!"
  println("AC")
else
  println("WA")
end

Kotlin

fun main(args: Array<String>){
  val s = readLine()!!
  println(if(s=="Hello,World!") "AC" else "WA")
}

Lua

s = io.read()

if s=="Hello,World!" then
  print("AC")
else
  print("WA")
end

Nim

import strutils

var s =  readLine(stdin)

if s=="Hello,World!":
  echo "AC"
else:
  echo "WA"

Objective-C

#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSString*)stringFromStdIn;
+(void)printf:(NSString*)format, ...;
@end

@implementation StdIO
+(NSString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if (length >= 1 && [result characterAtIndex:length-1] == '\n') {
        [result deleteCharactersInRange:NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    va_end(arguments);
}
@end

int main() {
    @autoreleasepool {
        NSString *S = [StdIO stringFromStdIn];
        if([S isEqualToString:@"Hello,World!"]){[StdIO printf:@"AC"];}
        else{[StdIO printf:@"WA"];}
    }
}

Common Lisp

(defun solve(s)
  (if (string= s "Hello,World!")
    "AC"
    "WA"))
(format t "~A~%" (solve(read-line)))

Ocaml

let () = Scanf.scanf "%s" (fun s -> print_endline @@ if s = "Hello,World!" then "AC" else "WA")

Octave

s=scanf('%s', 'C');

if strcmp(s,'Hello,World!')
  printf('AC');
else
  printf('WA');
end

Pascal

program abc215a;
uses SysUtils;
var
  s: string;
begin
  readln(s);
  if s='Hello,World!' then writeln('AC') else writeln('WA');
end.

Perl

my $s=<>;
chomp($s);
print $s eq "Hello,World!"?"AC":"WA";

Raku

my $s;
$s=get;
say $s eq "Hello,World!"??"AC"!!"WA";

PHP

<?php
fscanf(STDIN, "%s", $s);
echo $s=="Hello,World!"?"AC":"WA"."\n";
?>

Prolog

get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).

main :-
  get_string(S),
  S == "Hello,World!" ->
    write('AC');
    write('WA').

:- main.

Racket

#lang racket
(define s (read-line))
(display (if (equal? s "Hello,World!") "AC" "WA"))
(newline)

Ruby

s = gets.chomp
puts (s=="Hello,World!") ? 'AC' : 'WA'

Rust

use proconio::input;

fn main() {
    input! {
      s: String,
    }
    let answer = if s=="Hello,World!" { "AC" } else { "WA" };
    println!("{}", answer)
}

Scala

object Main {
  def main(args:Array[String]) = {
    val s = io.StdIn.readLine
    println(if(s=="Hello,World!") "AC" else "WA")
  }
}

Scheme

(define s (read-line))
(display (if (equal? s "Hello,World!") "AC" "WA"))
(newline)

Standard ML

val SOME s = TextIO.inputLine TextIO.stdIn

val () =
  print(if s = "Hello,World!\n" then "AC\n" else "WA\n")

Swift

let s=readLine()!
print(s=="Hello,World!" ? "AC" : "WA")

Typescript

import * as fs from 'fs';
 
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const s = input[0];
const ac = new String("Hello,World!");

console.log(s==ac?"AC":"WA")

Visual Basic

module abc215a
  sub Main(ByVal args() as String)
    dim s as string
    s=Console.ReadLine()
    Console.Write(IF(s="Hello,World!","AC","WA"))
  end sub
end module

Zsh

read s

if [ $s = "Hello,World!" ]; then
    echo "AC"
else
    echo "WA"
fi

posted:
last update: