관리 메뉴

moozi

끝말잇기게임 본문

C++

끝말잇기게임

moozi 2015. 11. 12. 17:03

#include <iostream>
#include <string>
using namespace std;

int main() {
 int n;
 cout << "게임에 참여하는 인원 : ";
 cin >> n;

 cin.ignore(1);//엔터키 한개 무시

 string  *names = new string[n];
 for (int i = 0; i < n; i++) {
  cout << i + 1 << "번째 참가자 이름 : ";
  getline(cin,names[i]);
  cout << names[i] << endl;

 }
 string firstWord = "";//첫번째단어
 string secondWord = "";//두번째단어
 int count = 0;//참가자순서
 cout << names[count] << " >> ";
 getline(cin, firstWord);//첫번째 단어

 while (true) {
  count++;//참가자순서증가
  if (count == n) {//참가자순서가 참여인원와 같아지면 다시 처음순서부터
   count = 0;
  }
  cout << names[count] << " >> ";
  getline(cin, secondWord);//두번째 단어
  int lastIndex = firstWord.length() - 2;
  if (firstWord.at(lastIndex) != secondWord.at(0) || firstWord.at(lastIndex + 1) != secondWord.at(1)) {
   cout << names[count] << "이(가) 졌습니다." << endl;
   break;
  }
  
  firstWord = secondWord;//두번째 단어를 첫번째로 옮김
  
 }


 return 0;
}

'C++' 카테고리의 다른 글

끝말잇기게임 클래스 버전  (0) 2015.11.17
파일입출력 클래스 버전 -주소록  (1) 2015.11.03
파일입출력예제 클래스버젼  (0) 2015.10.30
파일입출력 예제  (0) 2015.10.27
Comments