Algorithm
Problem Name: beecrowd | 2765
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2765
Coming Input and Output
By Roberto A. Costa Jr, UNIFEI Brazil
Timelimit: 1
Your teacher would like to make a program with the following characteristics:
- Read a sentence that will have a comma in the middle of the text;
- Print the first part of the sentence;
- Print the second part of the sentence.
Input
The input consists of several test files. In each test file there is one line. The line has a phrase with a maximum of 100 characters (may have white space) and a comma. As shown in the following input example.
Output
For each file in the entry, you have an output file. The output file has two lines according to steps 2 and 3. As shown in the following output example.
Input Samples | Output Samples |
O URI, eh o melhor |
O URI eh o melhor |
Bem vindo, ja vai!! |
Bem vindo ja vai!! |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[500];
int i=0, j, x;
while (fgets(str, 500, stdin) !=0)
{
x=strlen(str);
i=0;
while (str[i]!=',')
{
printf("%c", str[i]);
++i;
}
printf("\n");
for (j=++i; j < x; ++j)
printf("%c", str[j]);
}
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cstdio>
#include<stack>
#include<queue>
#include<math.h>
#include <utility>
#include <sstream>
#include<bitset>
using namespace std;
typedef long long ll;
typedef std::vector < double> vi;
#define PI acos(-1)
#define E 2.718281828459
int main(int argc, char** argv) {
string str;
getline(cin,str);
for(int i=0;i < str.length();i++)
{
if(str[i]==',')cout << endl;
else cout << str[i];
}
cout << endl;
}
Copy The Code &
Try With Live Editor
Input
Output
#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);
//DD/MM/AA
String[] a = new String[4];
a = sc.nextLine().split(",");
System.out.printf("%s\n%s\n",a[0],a[1]);
sc.close();
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const [text] = readFileSync("/dev/stdin", "utf8").split("\n")
console.log(text.replace(",", "\n"))
Copy The Code &
Try With Live Editor
Input
Output
#5 Code Example with Python Programming
Code -
Python Programming
while True:
try:
c = input()
c = c.split(',')
for i in c:
print(i)
except EOFError:
break
Copy The Code &
Try With Live Editor
Input
Output