al__nasim

sms typing

Jun 13th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. //uva 11530-sms typing
  2. #include<stdio.h>
  3. int main()
  4. {
  5. char type[100];
  6.  
  7. int count,i,j,sum = 0,T;
  8.  
  9. scanf("%d",&T);
  10. getchar();
  11.  
  12. for(j=1; j<=T; j++)
  13. {
  14. sum = 0;
  15. gets(type);
  16.  
  17. for(i=0; type[i] != '\0'; i++)
  18. {
  19. if(type[i] >= 'a' && type[i] <= 'c')
  20. {
  21. if(type[i] == 'a')
  22. count = 1;
  23. else if(type[i] == 'b')
  24. count = 2;
  25. else
  26. count = 3;
  27. }
  28. else if(type[i] >= 'd' && type[i] <= 'f')
  29. {
  30. if(type[i] == 'd')
  31. count = 1;
  32. else if(type[i] == 'e')
  33. count = 2;
  34. else
  35. count = 3;
  36. }
  37. else if(type[i] >= 'g' && type[i] <= 'i')
  38. {
  39. if(type[i] == 'g')
  40. count = 1;
  41. else if(type[i] == 'h')
  42. count = 2;
  43. else
  44. count = 3;
  45. }
  46. else if(type[i] >= 'j' && type[i] <= 'l')
  47. {
  48. if(type[i] == 'j')
  49. count = 1;
  50. else if(type[i] == 'k')
  51. count = 2;
  52. else
  53. count = 3;
  54. }
  55. else if(type[i] >= 'm' && type[i] <= 'o')
  56. {
  57. if(type[i] == 'm')
  58. count = 1;
  59. else if(type[i] == 'n')
  60. count = 2;
  61. else
  62. count = 3;
  63. }
  64. else if(type[i] >= 'p' && type[i] <= 's')
  65. {
  66. if(type[i] == 'p')
  67. count = 1;
  68. else if(type[i] == 'q')
  69. count = 2;
  70. else if(type[i] == 'r')
  71. count = 3;
  72. else
  73. count = 4;
  74. }
  75. else if(type[i] >= 't' && type[i] <= 'v')
  76. {
  77. if(type[i] == 't')
  78. count = 1;
  79. else if(type[i] == 'u')
  80. count = 2;
  81. else
  82. count = 3;
  83. }
  84. else if(type[i] >= 'w' && type[i] <= 'z')
  85. {
  86. if(type[i] == 'w')
  87. count = 1;
  88. else if(type[i] == 'x')
  89. count = 2;
  90. else if(type[i] == 'y')
  91. count = 3;
  92. else
  93. count = 4;
  94. }
  95. else if(type[i] == ' ')
  96. count = 1;
  97.  
  98. sum = sum + count;
  99.  
  100. }
  101.  
  102. printf("Case #%d: %d\n",j,sum);
  103. }
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment