PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CCBCHBON0000001. Dừng tại số âm đầu tiên (Stop at the First Negative Number)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dừng tại số âm đầu tiên (Stop at the First Negative Number)
Stop at the First Negative Number
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , find the first 1-based position whose value is negative. Print -1 if there is none, including . This exercise practices exiting a loop with break.
Input
The first value is , followed by exactly integers separated by whitespace. Every .
Output
Print the first negative position, or -1.
Subtasks
-
Subtask 1 (20%): ; .
-
Subtask 2 (30%): ; .
-
Subtask 3 (50%): ; .
Examples
Example 1
Input:
5
2 0 -4 -7 9
Output:
3
Explanation:
Scan left to right; the first negative value determines the reported position.
Example 2
Input:
0
Output:
-1
Explanation:
Scan left to right; the first negative value determines the reported position.