Algorithm


Problem Name: URI Online Judge | 2760

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2760

String Input and Output

 

By Roberto A. Costa Jr, UNIFEI BR Brazil

Timelimit: 1

Your teacher would like to make a program with the following characteristics:

  1. Create 3 variables to store a phrase of up to 100 characters;
  2. Read a sentence for the first variable;
  3. Read a sentence for the second variable;
  4. Read a sentence for the third variable;
  5. Print the first variable read in step 2, the second variable read in step 3, the third variable read in step 4. Be sure to skip line;
  6. Print the first variable read in step 3, the second variable read in step 4, the third variable read in step 2. Be sure to skip line;
  7. Print the first variable you read in step 4, the second variable you read in step 2, the third variable you read in step 3. Be sure to skip line;
  8. Repeat procedure 5, printing only 10 characters of each variable.

 

Input

 

The input consists of several test files. Each test file has three rows. In the first line has a variable A that stores a phrase of up to 100 characters. In the second line has a variable B that stores a phrase of up to 100 characters. In the third line has a variable C that stores a phrase of up to 100 characters. As shown in the following input example.

 

Output

 

For each file in the input, you have an output file. The output file has four rows as described in items 5, 6, 7, and 8. As shown in the following output example.

 

 

 

Input Samples Output Samples

Roberto

Carlos

Aldo

RobertoCarlosAldo

CarlosAldoRoberto

AldoRobertoCarlos

RobertoCarlosAldo

 

 

 

aaaa bbbb cccc

cccc

xxxxx xxxx xx

aaaa bbbb ccccccccxxxxx xxxx xx

ccccxxxxx xxxx xxaaaa bbbb cccc

xxxxx xxxx xxaaaa bbbb cccccccc

aaaa bbbb ccccxxxxx xxxx

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main()
{
    char var1[101];
    char var2[101];
    char var3[101];
    int i;

    setbuf(stdin, NULL);
    scanf(" %[^\n]", var1);
    setbuf(stdin, NULL);
    scanf(" %[^\n]", var2);
    setbuf(stdin, NULL);
    scanf(" %[^\n]", var3);

    printf("%s%s%s\n", var1, var2, var3);
    printf("%s%s%s\n", var2, var3, var1);
    printf("%s%s%s\n", var3, var1, var2);

    i = 0;

    while(var1[i] != '\0' && i  <  10)
    {
        printf("%c",var1[i]);
        i++;
    }

    i = 0;

    while(var2[i] != '\0' && i  <  10)
    {
        printf("%c",var2[i]);
        i++;
    }

    i = 0;

    while(var3[i] != '\0' && i  <  10)
    {
        printf("%c",var3[i]);
        i++;
    }

    printf("\n");
    
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
Roberto Carlos Aldo

Output

x
+
cmd
RobertoCarlosAldo CarlosAldoRoberto AldoRobertoCarlos RobertoCarlosAldo

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
    string a, b, c;
    getline(cin, a);
    getline(cin, b);
    getline(cin, c);
    cout << a << b << c << endl;
    cout << b << c << a << endl;
    cout << c << a << b << endl;
    cout << a.substr(0, 10) << b.substr(0, 10) << c.substr(0, 10) << endl;
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
Roberto Carlos Aldo

Output

x
+
cmd
RobertoCarlosAldo CarlosAldoRoberto AldoRobertoCarlos RobertoCarlosAldo

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;
import java.util.Locale;
public class Main {
	public static void main(String[] args) {
		Locale.setDefault(new Locale("en", "US"));
		Scanner sc = new Scanner(System.in);

		String[] a = new String[40];
		String input = sc.nextLine();
		a = input.split("");
		int ta=a.length;
		
		String[] b = new String[40];
		input = sc.nextLine();
		b = input.split("");
		int tb=b.length;
		
		String[] c = new String[40];
		input = sc.nextLine();
		c = input.split("");
		int tc=c.length;
		
		for(int i=0 ; i  <  ta ; i++) System.out.printf("%s",a[i]);
		for(int i=0 ; i  <  tb; i++) System.out.printf("%s",b[i]);
		for(int i=0 ; i  <  tc; i++) System.out.printf("%s",c[i]);
		System.out.println();
		
		for(int i=0 ; i  <  tb ; i++) System.out.printf("%s",b[i]);
		for(int i=0 ; i  <  tc; i++) System.out.printf("%s",c[i]);
		for(int i=0 ; i  <  ta; i++) System.out.printf("%s",a[i]);
		System.out.println();
		
		for(int i=0 ; i  <  tc; i++) System.out.printf("%s",c[i]);
		for(int i=0 ; i  <  ta; i++) System.out.printf("%s",a[i]);
		for(int i=0 ; i  <  tb; i++) System.out.printf("%s",b[i]);
		System.out.println();
		
		if(ta>10)ta=10;
		if(tb>10)tb=10;
		if(tc>10)tc=10;
		for(int i=0 ; i < ta; i++) System.out.printf("%s",a[i]);
		for(int i=0 ; i  <  tb; i++) System.out.printf("%s",b[i]);
		for(int i=0 ; i  <  tc; i++) System.out.printf("%s",c[i]);
		System.out.println();
		
		sc.close(>;
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
Roberto Carlos Aldo

Output

x
+
cmd
RobertoCarlosAldo CarlosAldoRoberto AldoRobertoCarlos RobertoCarlosAldo

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const [A, B, C] = readFileSync("/dev/stdin", "utf8").split("\n")

console.log("%s%s%s", A, B, C)
console.log("%s%s%s", B, C, A)
console.log("%s%s%s", C, A, B)
console.log("%s%s%s", A.substring(0, 10), B.substring(0, 10), C.substring(0, 10))
Copy The Code & Try With Live Editor

Input

x
+
cmd
Roberto Carlos Aldo

Output

x
+
cmd
RobertoCarlosAldo CarlosAldoRoberto AldoRobertoCarlos RobertoCarlosAldo

#5 Code Example with Python Programming

Code - Python Programming


a = input()
b = input()
c = input()
print('%s%s%s' %(a, b, c))
print('%s%s%s' %(b, c, a))
print('%s%s%s' %(c, a, b))
print('%s%s%s'%(a[:10], b[:10], c[:10]))

Copy The Code & Try With Live Editor

Input

x
+
cmd
Roberto Carlos Aldo

Output

x
+
cmd
RobertoCarlosAldo CarlosAldoRoberto AldoRobertoCarlos RobertoCarlosAldo
Advertisements

Demonstration


Previous
#2759 Beecrowd Online Judge Solution 2759 Input and Output Character Solution in C, C++, Java, Js and Python
Next
#2761 Beecrowd Online Judge Solution 2761 Input and Output of Various Types Solution in C, C++, Java, Js and Python