Algorithm


Problem Name: beecrowd | 2763

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

CPF 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. Read the data of a CPF in the format XXX.YYY.ZZZ-DD;
  2. Print the four numbers, one value per line.

 

Input

 

The entry consists of several test files. In each test file there is one line. The line has the following format XXX.YYY.ZZZ-DD, where XXX, YYY, ZZZ, DD are integers. As shown in the following input example.

 

Output

 

For each file in the entry, you have an output file. The output file has four rows with an integer in each of them as it has been entered. As shown in the following output example.

 

 

 

Input Samples Output Samples

000.000.000-00

000

000

000

00

 

 

 

320.025.102-01

320

025

102

01

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int x, y, z, d;

    while (scanf("%d.%d.%d-%d", &x, &y, &z, &d) != EOF)
    {
        printf("%03d\n%03d\n%03d\n%02d\n", x, y, z, d);
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
000.000.000-00

Output

x
+
cmd
000 000 000 00

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
using namespace std;
int main()
{
    int x , y , z , d;
    scanf("%d.%d.%d-%d" , &x , &y , &z , &d);
    if(x>=100)
        cout << x << endl;
    else if(x>=10 && x <100>
        cout << "0" << x << endl;
    else
        cout << "00" << x << endl;

    if(y>=100)
        cout << y << endl;
    else if(y>=10 && y <100>
        cout << "0" << y << endl;
    else
        cout << "00" << y << endl;
    if(z>=100)
        cout << z << endl;
    else if(z >=10 && z <100>
        cout << "0" << z << endl;
    else
        cout << "00" << z << endl;

    if(d>=10)
        cout << d << endl;
    else
        cout << "0"<< d << endl;
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
000.000.000-00

Output

x
+
cmd
000 000 000 00

#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);
		
		//XXX.YYY.ZZZ-DD
		String[] cpf = new String[4]; 
		cpf = sc.nextLine().split("\\.|-");
		for(int i=0; i  <  cpf.length ; i++)
			System.out.printf("%s\n",cpf[i]);
		sc.close();
	}
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
000.000.000-00

Output

x
+
cmd
000 000 000 00

#4 Code Example with Javascript Programming

Code - Javascript Programming


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

const splitCPFCode = (cpf = "") => cpf.split(/[-.]/)

function main() {
	const splitedCPFCode = splitCPFCode(input)
	console.log(splitedCPFCode.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
000.000.000-00

Output

x
+
cmd
000 000 000 00

#5 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        cpf = input()
        cpf = cpf.replace('-', '.')
        cpf = cpf.split('.')
        for i in cpf:
            print(i)
        
    except EOFError:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
000.000.000-00

Output

x
+
cmd
000 000 000 00
Advertisements

Demonstration


Previous
#2762 Beecrowd Online Judge Solution 2762 Input and Output 6 Solution in C, C++, Java, Js and Python
Next
#2764 Beecrowd Online Judge Solution 2764 Date Input and Output Solution in C, C++, Java, Js and Python