Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. /* Rebekah Flowers 11675474 keys.c
  2. Write a program that determines how many key strokes each finger will type in an input.*/
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int main(void)
  7. {
  8. /*input will never be longer than 50 characters so the string is 51 to account for the NULL*/
  9. char input[51];
  10. /*Initializing total values for strings then total values for keystrokes left and right; seperated into
  11. different int commands for organizations. */
  12. int totalStrings = 0, totalStringsRight = 0, totalStringsLeft = 0;
  13. int totalStrokes = 0, totalLeftIndex = 0, totalLeftMiddle = 0, totalLeftRing = 0, totalLeftPinky = 0;
  14. int totalRightIndex = 0, totalRightMiddle = 0, totalRightRing = 0, totalRightPinky = 0;
  15.  
  16. //Loop runs until ctrl-D is pressed
  17. int loopLen, i, count, left, right;
  18.  
  19. printf("Input: ");
  20. while (!feof(stdin)) {
  21.  
  22. scanf("%s", input);
  23. loopLen = strlen(input);
  24. totalStrings ++;
  25. right = 0;
  26. left = 0;
  27. for (i = 0; i < loopLen; i++){
  28. //If and else if statements to count the totals. The left and right variables are used to calculate the strings using only one hand.
  29. //Right Pinky:
  30. if (input[i] == 48 || input[i] == 58 || input[i] == 59 || input[i] == 124 || input[i] == 92 || input[i] == 63 || input[i] == 47 || input[i] == 93 ||
  31. input[i] == 91 || input[i] == 41 || input[i] == 112 || input[i] == 80 || input[i] == 123 || input[i] == 125 || input[i] == 61 || input[i] == 43 ||
  32. input[i] == 45 || input[i] == 95 || input[i] == 39 || input[i] == 34) {
  33. totalRightPinky++;
  34. totalStrokes++;
  35. right++;
  36. if (input[i] == 58 || input[i] == 124 || input[i] == 63 || input[i] == 41|| input[i] == 80 || input[i] == 123 || input[i] == 125 ||
  37. input[i] == 43 || input[i] == 95 || input[i] == 34){
  38. totalLeftPinky++;
  39. totalStrokes++;
  40. left++;
  41. }
  42. }
  43. //Right Ring:
  44. else if (input[i] == 40 || input[i] == 57 || input[i] == 79 || input[i] == 111 || input[i] == 76 || input[i] == 108 || input[i] == 46 || input[i] == 62) {
  45. totalRightRing++;
  46. totalStrokes++;
  47. right++;
  48. if (input[i] == 40 || input[i] == 79 || input[i] == 76 || input[i] == 62){
  49. totalLeftPinky++;
  50. totalStrokes++;
  51. left++;
  52. }
  53. }
  54. //Right Middle:
  55. else if (input[i] == 56 || input[i] == 42 || input[i] == 73 || input[i] == 105 || input[i] == 75 || input[i] == 107 || input[i] == 60 || input[i] == 44) {
  56. totalRightMiddle++;
  57. totalStrokes++;
  58. right++;
  59. if (input[i] == 42 || input[i] == 73 || input[i] == 75 || input[i] == 60){
  60. totalLeftPinky++;
  61. totalStrokes++;
  62. left++;
  63. }
  64. }
  65. //Right Index:
  66. else if (input[i] == 54 || input[i] == 55 || input[i] == 38 || input[i] == 94 || input[i] == 85 || input[i] == 117 || input[i] == 89 ||
  67. input[i] == 121 || input[i] == 72 || input[i] == 104 || input[i] == 74 || input[i] ==106 || input[i] == 78 || input[i] == 110 || input[i] == 77 || input[i] == 109) {
  68. totalRightIndex++;
  69. totalStrokes++;
  70. right++;
  71. if (input[i] == 38 || input[i] == 94 || input[i] == 85 || input[i] == 89 || input[i] == 72 || input[i] == 74 || input[i] == 78 || input[i] == 77){
  72. totalLeftPinky++;
  73. totalStrokes++;
  74. left++;
  75. }
  76. }
  77. //Left Pinkie:
  78. else if (input[i] == 96 || input[i] == 126 || input[i] == 49 ||input[i] == 33 || input[i] == 81 || input[i] == 113 || input[i] == 65 || input[i] == 97 ||
  79. input[i] == 90 || input[i] == 122) {
  80. totalLeftPinky++;
  81. totalStrokes++;
  82. left++;
  83. if (input[i] == 96 || input[i] == 33 || input[i] == 81 || input[i] == 65 || input[i] == 90){
  84. totalRightPinky++;
  85. totalStrokes++;
  86. right++;
  87. }
  88. }
  89. //Left Ring:
  90. else if (input[i] == 2 || input[i] == 64 || input[i] == 87 || input[i] == 119 || input[i] == 83 || input[i] == 115 || input[i] == 88 || input[i] == 120) {
  91. totalLeftRing++;
  92. totalStrokes++;
  93. left++;
  94. if (input[i] == 64 || input[i] == 87 || input[i] == 83 || input[i] == 88 ){
  95. totalRightPinky++;
  96. totalStrokes++;
  97. right++;
  98. }
  99. }
  100. //Left Middle:
  101. else if (input[i] == 51 || input[i] == 35 || input[i] == 69 || input[i] == 101 || input[i] == 68 || input[i] == 100 || input[i] == 67 || input[i] == 99) {
  102. totalLeftMiddle++;
  103. totalStrokes++;
  104. left++;
  105. if (input[i] == 35 || input[i] == 69 || input[i] == 68 || input[i] == 67){
  106. totalRightPinky++;
  107. totalStrokes++;
  108. right++;
  109. }
  110. }
  111. //Left Index:
  112. else if (input[i]== 52 || input[i]== 53 || input[i]== 36 || input[i]== 37 || input[i] == 84 || input[i]== 116 || input[i]== 82 || input[i]== 114 ||
  113. input[i]== 70 || input[i]== 102 || input[i]== 71 || input[i]== 103 || input[i]== 86 || input[i]== 118 || input[i]== 66 || input[i]== 98) {
  114. totalLeftIndex++;
  115. totalStrokes++;
  116. left++;
  117. if (input[i]== 36 || input[i]== 37 || input[i]== 84 || input[i]== 82 || input[i] == 70 || input[i]== 71 || input[i]== 86 || input[i]== 66){
  118. totalRightPinky++;
  119. totalStrokes++;
  120. right++;
  121. }
  122. }
  123. }
  124. //These if statements determine whether a string uses only the right or left hand and adds to the total. When the loop runs the temporary left and right variables reset to 0.
  125. if (right == 0 && left >= 1)
  126. totalStringsLeft++;
  127. if (left == 0 && right >= 1)
  128. totalStringsRight++;
  129. }
  130.  
  131. printf("\n%d strings entered\n %d keys typed using only the left hand\n %d keys typed using only the right hand\n", totalStrings, totalStringsLeft, totalStringsRight);
  132. printf("%d total keystrokes\n %d - Left index\n %d - Left middle\n %d - Left ring\n %d - Left pinky\n", totalStrokes, totalLeftIndex, totalLeftMiddle, totalLeftRing, totalLeftPinky);
  133. printf(" %d - Right index\n %d - Right middle\n %d - Right ring\n %d - Right pinky\n",totalRightIndex, totalRightMiddle, totalRightRing, totalRightPinky);
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement