Developer/C

array 예제

김민수63 2012. 7. 13. 20:23
반응형

 

 

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

int main()
{
 int i,flag=0;
 char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"},st[10];
 printf("Input: ");
 gets(st);
 printf("Output: ");
 for(i=0;i<12;i++){
  if(strcmp(st,month[i])==0){
   flag=1;
   break;
  }
 }
 if(flag==1){
  switch(i){
  case 0:
   puts("Yes, It's 1st month in the year.");
   break;
  case 1:
   puts("Yes, It's 2nd month in the year.");
   break;
  case 2:
   puts("Yes, It's 3rd month in the year.");
   break;
  case 11:
   puts("Yes, It's last month in the year.");
   break;
  default:
   printf("Yes, It's %dth month in the year.\n",i+1);
   break;
  }
 }
 else puts("Invalid month name.");
 return 0;
}

 

연대 컴공친구가 준 문제다. 그냥 딱보면 답 나온다. (근데 문제가 영어다 ㅡㅡ 이래서 ACM-ICPC같은건 어떻게 푸는거지 하는 생각이 든다.)

요는 2차원행렬을 이용하여 달들의 이름을 적고, 그것을 입력받은 다음에 케이스문을 이용하여 몇번째 달인지를 출력해주는 것이다. 아니면 아니라고 하고.

반응형