The TransCompilator

Solved LeetCode program · 65 of 1,000

#0065 · Valid Number

Hard String chunk-02.md

Original English source

The text is "2e10". The last is the last position of text. The position is 0. The digits is 0. The expcount is 0. The exponentseen is 0. The valid is 1.
Repeat while position is at most last.
If character position of text is not 32, break. Add 1 to position.

If position is at most last and (character position of text is 43 or character position of text is 45), add 1 to position.
Repeat while position is at most last and character position of text is between "0" and "9".
Add 1 to digits. Add 1 to position.

If position is at most last and character position of text is 46.
Add 1 to position.
Repeat while position is at most last and character position of text is between "0" and "9".
Add 1 to digits. Add 1 to position.

If position is at most last and (character position of text is 101 or character position of text is 69).
Set exponentseen to 1. Add 1 to position. If position is at most last and (character position of text is 43 or character position of text is 45), add 1 to position.
Repeat while position is at most last and character position of text is between "0" and "9".
Add 1 to expcount. Add 1 to position.

If exponentseen is 1 and expcount is 0, set valid to 0.
Repeat while position is at most last.
If character position of text is not 32, set valid to 0, break. Add 1 to position.

If digits is 0, set valid to 0. If valid is 1, report true. Otherwise, report false.

Open in Playground Browse all 1,000 problems

Expected stdout

true