2014年8月18日星期一

[UVa] 11530 - SMS Typing

/*
  要注意,Judge測試的Case數很大
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i,j,cases=0,count=0;
int main(){
  scanf("%d",&cases);
  char c[1000]={'\0'};
  getchar();
  for(i=0;i<cases;i++){
    fgets(c,sizeof(c),stdin);
    count=0;
    for(j=0;j<sizeof(c);j++){
      if(c[j]=='a' || c[j]=='d' || c[j]=='g' || c[j]=='j' || c[j]=='m' || 
         c[j]=='p' || c[j]=='t' || c[j]=='w' || c[j]==' ')count++;
      if(c[j]=='b' || c[j]=='e' || c[j]=='h' || c[j]=='k' ||
         c[j]=='n' || c[j]=='q' || c[j]=='u' || c[j]=='x')count+=2;
      if(c[j]=='c' || c[j]=='f' || c[j]=='i' || c[j]=='l' ||
         c[j]=='o' || c[j]=='r' || c[j]=='v' || c[j]=='y')count+=3;
      if(c[j]=='s' || c[j]=='z')count+=4;
    }
    printf("Case #%d: %d\n",i+1,count);
    for(j=0;j<1000;j++)c[j]='\0'; /*renew the array!*/
  }
  /*
  for(i=0;i<cases;i++){
    printf("Case #%d: %d\n",i+1,s[i]);
  }
  */
  return 0;
}

沒有留言: