Bessie đã đổ ra bộ sưu tập của cô với N (1<=N<=80) hạt xanh và cam (biểu diễn bởi 0 và 1) xuống sàn.
Bessie dọn dẹp sự lộn xộn bằng cách sắp xếp chúng lại thành 1 đường thẳng dài. Cô muốn đếm số lần hai hạt
liên tiếp khác màu nhau. Hãy giúp cô thực hiện điều này.
INPUT:
* Dòng 1: 1 số nguyên: N
* Dòng 2: Dòng 2 chứa N số nguyên, mỗi số là 0 hoặc 1
OUTPUT:
* Dòng 1: 1 số nguyên biểu diễn số lần hai hạt liên tiếp khác màu.
VÍ DỤ:
INPUT:
6
1 0 0 1 1 1
SAMPLE OUTPUT :
2
Bessie has spilled her collection of N (1 <= N <= 80) blue and orange
cowbeads (represented as 1s and 0s, respectively, in the human world) on
the floor. She cleans up the mess by arranging the beads into a long line.
She then counts the number of times a blue bead is next to an orange bead
and vice versa, but is not sure if she is correct. Write a program to
validate Bessie's count.
PROBLEM NAME: countbead
INPUT FORMAT:
* Line 1: A single integer: N
* Line 2: Line 2 contains N integers, each of which is 0 or 1
SAMPLE INPUT (file countbead.in):
6
1 0 0 1 1 1
INPUT DETAILS:
There are six beads in total: the first bead in the line is a blue bead,
followed by two orange beads, and finally by three blue beads.
OUTPUT FORMAT:
* Line 1: A single integer describing the number of occurrences that a
blue bead is next to an orange bead and vice versa.
SAMPLE OUTPUT (file countbead.out):
2
OUTPUT DETAILS:
There are two times in the line that two differently colored beads are next
to each other.has spilled her collection of N (1 <= N <= 80) blue and orange
cowbeads (represented as 1s and 0s, respectively, in the human world) on
the floor. She cleans up the mess by arranging the beads into a long line.
She then counts the number of times a blue bead is next to an orange bead
and vice versa, but is not sure if she is correct. Write a program to
validate Bessie's count.
PROBLEM NAME: countbead
INPUT FORMAT:
* Line 1: A single integer: N
* Line 2: Line 2 contains N integers, each of which is 0 or 1
SAMPLE INPUT (file countbead.in):
6
1 0 0 1 1 1
INPUT DETAILS:
There are six beads in total: the first bead in the line is a blue bead,
followed by two orange beads, and finally by three blue beads.
OUTPUT FORMAT:
* Line 1: A single integer describing the number of occurrences that a
blue bead is next to an orange bead and vice versa.
SAMPLE OUTPUT (file countbead.out):
2
OUTPUT DETAILS:
There are two times in the line that two differently colored beads are next
to each other.
cowbeads (represented as 1s and 0s, respectively, in the human world) on
the floor. She cleans up the mess by arranging the beads into a long line.
She then counts the number of times a blue bead is next to an orange bead
and vice versa, but is not sure if she is correct. Write a program to
validate Bessie's count.
PROBLEM NAME: countbead
INPUT FORMAT:
* Line 1: A single integer: N
* Line 2: Line 2 contains N integers, each of which is 0 or 1
SAMPLE INPUT (file countbead.in):
6
1 0 0 1 1 1
INPUT DETAILS:
There are six beads in total: the first bead in the line is a blue bead,
followed by two orange beads, and finally by three blue beads.
OUTPUT FORMAT:
* Line 1: A single integer describing the number of occurrences that a
blue bead is next to an orange bead and vice versa.
SAMPLE OUTPUT (file countbead.out):
2
OUTPUT DETAILS:
There are two times in the line that two differently colored beads are next
to each other.has spilled her collection of N (1 <= N <= 80) blue and orange
cowbeads (represented as 1s and 0s, respectively, in the human world) on
the floor. She cleans up the mess by arranging the beads into a long line.
She then counts the number of times a blue bead is next to an orange bead
and vice versa, but is not sure if she is correct. Write a program to
validate Bessie's count.
PROBLEM NAME: countbead
INPUT FORMAT:
* Line 1: A single integer: N
* Line 2: Line 2 contains N integers, each of which is 0 or 1
SAMPLE INPUT (file countbead.in):
6
1 0 0 1 1 1
INPUT DETAILS:
There are six beads in total: the first bead in the line is a blue bead,
followed by two orange beads, and finally by three blue beads.
OUTPUT FORMAT:
* Line 1: A single integer describing the number of occurrences that a
blue bead is next to an orange bead and vice versa.
SAMPLE OUTPUT (file countbead.out):
2
OUTPUT DETAILS:
There are two times in the line that two differently colored beads are next
to each other.
#include<iostream>
int main()
{
int n,a[82], dem =0;
std::cin>>n;
for( int i=1;i<=n;++i)
std::cin>>a[i];
for ( int i =1;i<n;++i)
if( a[i]^a[i+1])
++dem;
std::cout<<dem;
//system("pause");
return 0;
}
0 comments:
Post a Comment