이게 행맨인가요?
행맨이란 말을 처음 들어봐서 그냥 요구사항에 따라 코딩해봤습니다.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int MatchChar(const char *pWord,char ch,int *matched);
int main(void)
{
const int MaxTrial=15;
const char *const pWord="concatenation";
const int wordLen=strlen(pWord);
int matchedCount=0;
int matchedIndice[16]={0,};
char ch;
int i ,idx;
const int y=wherey();
for(i=1 ;i<=wordLen ;i=i+1){
putchar('_');
}
printf("\n : Input a Character. ");
for(i=1 ;i<=MaxTrial ;i=i+1){
gotoxy(1,y+1);
printf("%2i/%2i",i,MaxTrial);
gotoxy(i+26,y+1);
ch=getche();
if((idx=MatchChar(pWord,ch,matchedIndice))>=0){
matchedCount=matchedCount+1;
gotoxy(idx+1,y);
putchar(ch);
if(matchedCount==wordLen) break;
}else if(wordLen-matchedCount>MaxTrial-i){
break;
}
}
gotoxy(1,y+2);
if(matchedCount==wordLen) {
printf("You Win!");
}else{
printf("Failed!");
}
getch();
return 0;
}
int MatchChar(const char *pWord,char ch,int *matched)
{
const char *p=pWord;
int index;
if(!pWord || !matched) return -1;
while(1){
p=strchr(p,ch);
if(!p) return -1;
index=p-pWord;
if(matched[index]==0){
matched[index]=1;
return index;
}else{
p=p+1;
}
}
}
ㅠ_ㅠ 님이 쓰신 글 :
: 그냥 단순한 씨 언어만으로 짠프로그램은 없을까요..
:
: 아직은 제가 초보라서 뭐가 뭔지 봐도 모르겠네요..ㅠ_ㅠ
:
: 초보자에 맞는게 필요한데..흑흑..
:
: 문제 다시 올려드릴게요..
:
: 행맨하는 프로그램을 작성하는건데 이 게임에서는 하나의 단어를 숨겨두고서 단지 그 단어의 길이만큼 밑줄을 화면에 표시한후, 사용자는 영문자를 입력함으로써 그 단어를 맞춰야 한다. 사용자가 하나의 문자를 입력할때마다, 숨겨진 단어에 그 문자가 포함되어 있는지를 확인한다. 만약 포함되어 있으면, 그 문자를 화면에 보여준다. 그 단어를 완전히 알아 맞출때까지 입력된 문자들의 수를 센다. 프로그램을 간단히 하기 위해 15번 이하의 시행에서 단어를 알아맞추면 이긴것으로 간주하여라.. 숨겨진 단어로 concatenation을 사용하여라.. 행맨그림은 문자로 만들라는데 어떻게 하는질 모르겠어요..ㅠ_ㅠ
:
: 고수님들 제발 부탁드려요..ㅠ_ㅠ
|