7.06.2017

패턴 인식: 4개의 동일 연속 번호

//C++로 시작하는 객체지향 프로그래밍 p.332 예제 7.24 - 패턴 인식 : 4개의 동일 연속 번호
#include <iostream>
using namespace std;

bool isConsecutiveFour (const int values[], int size);
int main(){
const int SIZE = 80;
int numbers[SIZE];

cout << "Enter the numbers: ";
int size, j = 0, k= 0;
cin >> size;

for (int i = 0; i < size; i++){
cin >> numbers[i];
}

if (isConsecutiveFour(numbers, size))
cout << "The series has consecutive fours" << endl;
else cout << "The series has no consecutive fours" << endl;

system("pause");
return 0;
}

bool isConsecutiveFour (const int values[], int size){
for (int i = 0; i < size - 3; i++){
bool isEqual = true;
for (int j = i; j < i + 3; j++){
if (values[j] != values[j+1]) {
isEqual = false;
break;
}
}
if (isEqual) return true;
}
return false;
}

댓글 없음:

댓글 쓰기