조회 수 978 추천 수 0 댓글 0

#include <stdio.h>
//#include <conio.h>
#include <string.h> 

char word[201];
char cut_word[201][201];
char end[4]={'E', 'N', 'D', '\0'};
int cnt[201]={0};

void set_word(void); //word 배열을 초기화하는 함수
void set_cut_word(int a); //cut_word 배열을 초기화하는 함수
 
int cut(void); //단어로 끊어내는 함수 
void line(int c); //알파벳 순으로 정렬하는 함수 
int what(int a, int b); //어떤 것이 앞 순서인지 판단하는 함수 
int main(void)
{
	int c=0, i, k;

	while(1)
	{
		scanf(" %[^\n]s", word);
		//gets(word);

		c=cut();

		if(c==-1) //END가 입력되면 종료 
		break;

		line(c);

		for(i=0; i<c; i++)
		{
	   		printf("%s : %d\n", cut_word[i], cnt[i]);
		}

		set_word();
		//strset(word, ' ');
		for(i=0; i<c; i++)
		{
			set_cut_word(i);
			//strset(cut_word[i], ' ');
			cnt[i]=0;
		}
	}
	 
	return 0;
}
void set_word(void)
{
	int i=0;
	while(word[i]!='\0')
	{
		word[i++]=' ';
	}
	word[i]=' ';
}
void set_cut_word(int a)
{
	int i=0;
	while(cut_word[a][i]!='\0')
	{
		cut_word[a][i++]=' ';
	}
	cut_word[a][i]=' ';
}
int cut(void)
{
	int i=0, j=0, k, a, b;
	char temp[50];

	for(k=0; ; k++)
	{
		if(word[k]==' ' || word[k]=='\0')
		{
			temp[j]='\0';

			if(strcmp(temp, end)==0) //END가 입력되면 종료 
				return -1;
		   	
			else if(i>0)
		   	{
		    	b=0;
		    	for(a=0; a<i; a++)
		    	{
		     		if(strcmp(temp, cut_word[a])==0) //앞에 같은 단어가 있을 경우 
		     		{
		      			cnt[a]++;
		      			b=1;
		     			break;
		     		}
		    	}
		    	if(b==0)
		  		{
		     		cnt[i]++;
		     		strcpy(cut_word[i++], temp);
		   		}
		  	}
		   	
		   	else
		   	{
		   		cnt[i]++;
		    	strcpy(cut_word[i++], temp);
		   	}
		   	
		   	if(word[k]=='\0') //입력된 문자열이 끝남 
		    	break;
		   
		   	j=0;
		   	k++;
		}

		if(word[k]!=' ')
	  		temp[j++]=word[k];
	}

	return i;
}
void line(int c)
{
	int i, j, aa, max;
	char temp[50];

	for(i=0; i<c-1; i++)
	{
		max=i;
		if(cut_word[i][0]!=' ')
		{
			for(j=i+1; j<c; j++)
			{
				if(what(max, j)==1) //앞 단어가 더 뒷 순서일 경우 
				{
		    		max=j;
		   		}
		  	}
		  	
		  	if(max!=i)
		  	{
			   	strcpy(temp, cut_word[i]);
			   	strcpy(cut_word[i], cut_word[max]);
			   	strcpy(cut_word[max], temp);
			   	
			   	aa=cnt[i];
			   	cnt[i]=cnt[max];
			   	cnt[max]=aa;
		  	}
	 	}
	  	//printf("----------------------------\n");
	}
}
int what(int a, int b)
{
	int i;

	for(i=0; ; i++)
	{
		if(cut_word[a][i]>cut_word[b][i] || cut_word[b][i]=='\0')
	  	{
	   		//printf("%s > %s \n", cut_word[a], cut_word[b]);
	   		return 1;
	  	}
	  	else if(cut_word[a][i]<cut_word[b][i] || cut_word[a][i]=='\0')
	  	{
	   		//printf("%s > %s \n", cut_word[b], cut_word[a]);
	   		return 0;
	  	}
	}
}



List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 글쓰기는 하루 5개, 댓글은 10개만 가능합니다. 좋은아빠되기 2019.02.15 293
공지 키보드 화살표값 출력 좋은아빠되기 2016.11.19 1067
공지 원하는 좌표에 값 출력하기 좋은아빠되기 2016.11.19 2380
공지 Python(파이썬) 학습 자료 PDF 1 file 좋은아빠되기 2014.12.10 10239
공지 dev C++ 텍스트 색상변경 WinApi사용(textcolor 대용) 좋은아빠되기 2014.06.07 4707
공지 DEV-C++ 기본 코드 좋은아빠되기 2013.06.19 8207
공지 무료 C++ 컴파일러(윈도우용) DEV-C++ 좋은아빠되기 2013.06.18 18937
공지 이클립스 C++ 설치 파일들 좋은아빠되기 2013.06.18 37825
330 정올 - 실력키우기 - 문자열 찾기(2514) 조정미 2018.01.03 237
329 정올 - 실력키우기 - 삽입정렬 횟수 세기(1814) 조정미 2018.01.03 321
328 정올 - 실력키우기 - 삽입정렬(1158) 조정미 2018.01.03 282
327 정올 - 실력키우기 - 선택정렬(1146) 조정미 2018.01.03 274
326 정올 - 실력키우기 - 팩토리얼(1309) 조정미 2018.01.02 410
325 정올 - 실력키우기 - 최대공약수와 최소공배수(1658) 조정미 2018.01.02 1311
» 정올 - 실력키우기 - 단어 세기(1516) 조정미 2018.01.02 978
323 정올 - 실력키우기 - 윤년(2085) 조정미 2017.12.30 226
322 정올 - 실력키우기 - 각 자리수의 합(2812) 조정미 2017.12.27 663
321 정올 - 실력키우기 - 각자리수의 역과 합(1009) 조정미 2017.12.27 468
320 정올 - 실력키우기 - 그릇(2604) 조정미 2017.12.27 555
319 정올 - 실력키우기 - 숫자삼각형(1641) 조정미 2017.12.27 979
318 정올 - 실력키우기 - 별삼각형3(1329) 조정미 2017.12.27 257
317 정올 - 실력키우기 - 별삼각형1(1523) 조정미 2017.12.27 258
316 정올 - 실력키우기 - 마방진(2074) 조정미 2017.12.27 275
315 정올 - 실력키우기 - 주사위 던지기2(1175) 조정미 2017.12.27 569
314 정올 - 실력키우기 - 주사위 던지기1(1169) 조정미 2017.12.23 923
313 정올 - 실력키우기 - 색종이(초) (1438) 조정미 2017.12.23 615
312 정올 - 실력키우기 - 버블정렬(1157) 조정미 2017.12.23 244
311 정올 - 실력키우기 - 카드게임(1311) 조정미 2017.12.23 1873
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 26 Next
/ 26