[ create a new paste ] login | about

Link: http://codepad.org/P3j0k5MD    [ raw code | output | fork ]

kabhwan - C++, pasted on Jun 17:
#include <stdio.h>

#define MAX_STRING_LENGTH		100
#define MAX_MATCH_STRING_LENGTH		20

bool check_match(char str[], char match[])
{
	int i, curr_match_idx = 0;

	// 전체 문자열을 한 번만 훑음( O(n) )
	for(i = 0 ; i < MAX_STRING_LENGTH ; i++)
	{
		// 모든 글자를 찾았는지 확인
		// 다 찾았다면 루프를 더 돌 필요가 없다
		if(match[curr_match_idx] == '\0')
			break;

		// curr_match_idx 번째 글자를 찾았을 때
		if(str[i] == match[curr_match_idx])
			curr_match_idx++;
	}

	// 모든 글자를 찾았음
	if(match[curr_match_idx] == '\0')
		return true;

	return false;
}

void get_input(char str[])
{
	printf("Type any letters whatever you want:");
	scanf("%s", str);
}

int main()
{
	char input_str[MAX_STRING_LENGTH];
	char match[MAX_MATCH_STRING_LENGTH] = "IloveKorea";

	//get_input(input_str);
	
	// codepad.org 에서는 standard input 을 못 받으므로 대신 처리
	// 아래 라인을 주석 처리하고 get_input 라인을 주석 해제하면 입력을 받아서 처리
	strcpy(input_str, "Iabcloabcjdvjse   sdkkjKjksdoancrjekka");

	if(check_match(input_str, match))
		printf("I love Korea\n");
		
	return 0;
}


Output:
1
I love Korea


Create a new paste based on this one


Comments: