HackerEarth – Read from STDIN, Write to STDOUT

Let’s start with this basic problem. We will be solving it and providing you with the solution in different programming languages.

Problem Statement:

Read different types of data from standard input, process them as shown in output format, and print the answer to standard output.

Input format:
The first line contains the integer N.
The second line contains the string S.

Output format:
The first line should contain N x 2.
The second line should contain the same string S.

Constraints:

0 <= N <= 10
1 <= S <= 15, where S length of string S

Solutions

C Programming:

#include <stdio.h>

int main()
{
	short n;
	char s[10];
	scanf("%d", &n);
	scanf("%s", &s);
	printf("%d\n%s", n*2, s);
	return 0;
}

Python:

n = int(input())
s = input()

print(n*2)
print(s)

Python Oneliner:

print(f"{int(input())*2}\n{input()}")

C++:

#include <iostream>
using namespace std;

int main() {
    int n;
	char s[10];
    cin >> n;
	cin >> s;
	cout << n*2 << "\n" << s;
    return 0;
}

Java:

import java.util.Scanner;

public class CodeWin
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String s = input.next();
        System.out.println(n*2 + "\n" + s);
    }
}

All of the above programs are tested on the HackerEarth platform at the time of writing this article. If you want the above solution in any other programming language, please let us know in the comments. We will add the solution to your requested programming language.

groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *