Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Rebekah Flowers 11675474 keys.c
- Write a program that determines how many key strokes each finger will type in an input.*/
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- /*input will never be longer than 50 characters so the string is 51 to account for the NULL*/
- char input[51];
- /*Initializing total values for strings then total values for keystrokes left and right; seperated into
- different int commands for organizations. */
- int totalStrings = 0, totalStringsRight = 0, totalStringsLeft = 0;
- int totalStrokes = 0, totalLeftIndex = 0, totalLeftMiddle = 0, totalLeftRing = 0, totalLeftPinky = 0;
- int totalRightIndex = 0, totalRightMiddle = 0, totalRightRing = 0, totalRightPinky = 0;
- //Loop runs until ctrl-D is pressed
- int loopLen, i, count, left, right;
- printf("Input: ");
- while (!feof(stdin)) {
- scanf("%s", input);
- loopLen = strlen(input);
- totalStrings ++;
- right = 0;
- left = 0;
- for (i = 0; i < loopLen; i++){
- //If and else if statements to count the totals. The left and right variables are used to calculate the strings using only one hand.
- //Right Pinky:
- 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 ||
- input[i] == 91 || input[i] == 41 || input[i] == 112 || input[i] == 80 || input[i] == 123 || input[i] == 125 || input[i] == 61 || input[i] == 43 ||
- input[i] == 45 || input[i] == 95 || input[i] == 39 || input[i] == 34) {
- totalRightPinky++;
- totalStrokes++;
- right++;
- if (input[i] == 58 || input[i] == 124 || input[i] == 63 || input[i] == 41|| input[i] == 80 || input[i] == 123 || input[i] == 125 ||
- input[i] == 43 || input[i] == 95 || input[i] == 34){
- totalLeftPinky++;
- totalStrokes++;
- left++;
- }
- }
- //Right Ring:
- 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) {
- totalRightRing++;
- totalStrokes++;
- right++;
- if (input[i] == 40 || input[i] == 79 || input[i] == 76 || input[i] == 62){
- totalLeftPinky++;
- totalStrokes++;
- left++;
- }
- }
- //Right Middle:
- 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) {
- totalRightMiddle++;
- totalStrokes++;
- right++;
- if (input[i] == 42 || input[i] == 73 || input[i] == 75 || input[i] == 60){
- totalLeftPinky++;
- totalStrokes++;
- left++;
- }
- }
- //Right Index:
- else if (input[i] == 54 || input[i] == 55 || input[i] == 38 || input[i] == 94 || input[i] == 85 || input[i] == 117 || input[i] == 89 ||
- 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) {
- totalRightIndex++;
- totalStrokes++;
- right++;
- 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){
- totalLeftPinky++;
- totalStrokes++;
- left++;
- }
- }
- //Left Pinkie:
- 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 ||
- input[i] == 90 || input[i] == 122) {
- totalLeftPinky++;
- totalStrokes++;
- left++;
- if (input[i] == 96 || input[i] == 33 || input[i] == 81 || input[i] == 65 || input[i] == 90){
- totalRightPinky++;
- totalStrokes++;
- right++;
- }
- }
- //Left Ring:
- 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) {
- totalLeftRing++;
- totalStrokes++;
- left++;
- if (input[i] == 64 || input[i] == 87 || input[i] == 83 || input[i] == 88 ){
- totalRightPinky++;
- totalStrokes++;
- right++;
- }
- }
- //Left Middle:
- 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) {
- totalLeftMiddle++;
- totalStrokes++;
- left++;
- if (input[i] == 35 || input[i] == 69 || input[i] == 68 || input[i] == 67){
- totalRightPinky++;
- totalStrokes++;
- right++;
- }
- }
- //Left Index:
- 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 ||
- input[i]== 70 || input[i]== 102 || input[i]== 71 || input[i]== 103 || input[i]== 86 || input[i]== 118 || input[i]== 66 || input[i]== 98) {
- totalLeftIndex++;
- totalStrokes++;
- left++;
- 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){
- totalRightPinky++;
- totalStrokes++;
- right++;
- }
- }
- }
- //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.
- if (right == 0 && left >= 1)
- totalStringsLeft++;
- if (left == 0 && right >= 1)
- totalStringsRight++;
- }
- 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);
- 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);
- printf(" %d - Right index\n %d - Right middle\n %d - Right ring\n %d - Right pinky\n",totalRightIndex, totalRightMiddle, totalRightRing, totalRightPinky);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement