0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaラーニングレベルアップ問題集の「1つのデータの入力」と「1行のデータの入力」をやってみた。

Posted at

paizaラーニングレベルアップ問題集の1つのデータの入力1行のデータの入力をやってみました。をやってみました。


問題
1つのデータの入力

1行のデータの入力


コードが1つの言語は2問共通のコードです。


C
1つのデータの入力
#include <stdio.h>

int main() {
	char s[101];
	scanf("%s", s);
	printf("%s\n", s);
	return 0;
}

1行のデータの入力
#include <stdio.h>

int main() {
	char s[102];
	printf("%s", fgets(s, sizeof(s), stdin));
	return 0;
}

C++
1つのデータの入力
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	cout << s << endl;
	return 0;
}

1行のデータの入力
#include <iostream>
using namespace std;

int main() {
	string s;
	getline(cin, s);
	cout << s << endl;
	return 0;
}

C#
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine(Console.ReadLine());
	}
}

Go
1つのデータの入力
package main
import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(s)
}

1行のデータの入力
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}

Java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.nextLine());
		sc.close();
	}
}

1つのデータの入力
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.next());
		sc.close();
	}
}

JavaScript
console.log(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Kotlin
fun main() {
	println(readLine())
}

1つのデータの入力
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	println(sc.next())
	sc.close()
}

PHP
<?php
	echo trim(fgets(STDIN)) . PHP_EOL;
?>

Perl
chomp(my $s = <STDIN>);
print "$s\n";

Python3
print(input())

Ruby
puts gets

Scala
import scala.io.StdIn._

object Main extends App{
	println(readLine())
}

Swift
print(readLine()!)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?