Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define FEEL_LEN 6
- #define STRUCT_MAX 20
- #define DAY_LEN 8
- typedef struct day{
- char date[DAY_LEN];
- char feeling[FEEL_LEN];
- int run;
- int walk;
- int stand;
- int sit;
- int lay;
- }day;
- int ReadFile(day List[],int max);
- void mCommon(day List[],int dCount);
- void output1(day List[],int dCount);
- int main(void){
- day days[STRUCT_MAX];
- int daysCount = ReadFile(days, STRUCT_MAX);
- mCommon(days, daysCount);
- output1(days, daysCount);
- return 0;
- }
- int ReadFile(day List[], int max){
- FILE *fp = fopen("001.txt", "r");
- if (fp == NULL){
- exit(2);
- }
- int i = 0;
- while(fscanf(fp, "%s %s %d %d %d %d %d", List[i].date,
- List[i].feeling, &List[i].run, &List[i].walk, &List[i].stand,
- &List[i].sit, &List[i].lay) == 7){
- i++;
- if(i == max){
- break;
- }
- }
- fclose(fp);
- return i;
- }
- void mCommon(day List[],int dCount){
- int count[4] = {0};
- int max, maxIndex;
- for(int i = 0; i < dCount; i++){
- if(strcmp(List[i].feeling, "great") == 0){
- count[0] += 1;
- }else if(strcmp(List[i].feeling, "bad") == 0){
- count[1] += 1;
- }else if(strcmp(List[i].feeling, "good") == 0){
- count[2] += 1;
- }else if(strcmp(List[i].feeling, "awesome") == 0){
- count[3] += 1;
- }
- }
- max = count[0];
- for(int i = 1; i < 4; i++){
- if(count[i] > max){
- max = count[i];
- maxIndex = i;
- }
- }
- if(maxIndex == 0){
- printf("The most common feeling is great appears %d\n", max);
- }else if(maxIndex == 1){
- printf("The most common feeling is bad appears %d\n", max);
- }else if(maxIndex == 2){
- printf("The most common feeling is good appears %d\n", max);
- }else if(maxIndex == 3){
- printf("The most common feeling is awesome appears %d\n", max);
- }
- }
- void output1(day List[], int dCount){
- FILE *outf = fopen("out.txt", "w");
- int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;
- float per1, per2, per3;
- for(int i = 0; i < dCount; i++){
- sum1 += List[i].run;
- sum2 += List[i].walk;
- sum3 += List[i].stand;
- sum4 += List[i].sit;
- sum5 += List[i].lay;
- per1 = List[i].run * 1.37;
- per2 = List[i].walk * 0.59;
- per3 = List[i].stand * 0.18;
- float sum = per1 + per2 + per3;
- printf("On day %.*s/%.*s/%.*s person was got: %0.2f\n", 2,
- 0 + List[i].date, 2, 2 + List[i].date, 4,
- 4 + List[i].date, sum);
- printf("Person was running for %d:%d\n", List[i].run / 60,
- List[i].run % 60);
- printf("Person was walking for %d:%d\n", List[i].walk / 60,
- List[i].walk % 60);
- printf("Person was standing for %d:%d\n", List[i].stand / 60,
- List[i].stand % 60);
- printf("Person was sitting for %d:%d\n", List[i].sit / 60,
- List[i].sit % 60);
- printf("Person was laying down for %d:%d\n", List[i].lay / 60,
- List[i].lay % 60);
- fprintf(outf, "On day %.*s/%.*s/%.*s person was got: %0.2f\n",
- 2, 0 + List[i].date, 2, 2 + List[i].date, 4,
- 4 + List[i].date, sum);
- fprintf(outf, "Person was running for %d:%d\n",
- List[i].run / 60, List[i].run % 60);
- fprintf(outf, "Person was walking for %d:%d\n",
- List[i].walk / 60, List[i].walk % 60);
- fprintf(outf, "Person was standing for %d:%d\n",
- List[i].stand / 60, List[i].stand % 60);
- fprintf(outf, "Person was sitting for %d:%d\n",
- List[i].sit / 60, List[i].sit % 60);
- fprintf(outf, "Person was laying down for %d:%d\n",
- List[i].lay / 60, List[i].lay % 60);
- }
- printf("Average time running is %d:%d\n", (sum1 / dCount) / 60,
- (sum1 / dCount) % 60);
- printf("Average time running is %d:%d\n", (sum2 / dCount) / 60,
- (sum2 / dCount) % 60);
- printf("Average time running is %d:%d\n", (sum3 / dCount) / 60,
- (sum3 / dCount) % 60);
- printf("Average time running is %d:%d\n", (sum4 / dCount) / 60,
- (sum4 / dCount) % 60);
- printf("Average time running is %d:%d\n", (sum5 / dCount) / 60,
- (sum5 / dCount) % 60);
- fprintf(outf, "Average time running is %d:%d\n", (sum1 / dCount) /
- 60, (sum1 / dCount) % 60);
- fprintf(outf, "Average time running is %d:%d\n", (sum2 / dCount) /
- 60, (sum2 / dCount) % 60);
- fprintf(outf, "Average time running is %d:%d\n", (sum3 / dCount) /
- 60, (sum3 / dCount) % 60);
- fprintf(outf, "Average time running is %d:%d\n", (sum4 / dCount) /
- 60, (sum4 / dCount) % 60);
- fprintf(outf, "Average time running is %d:%d\n", (sum5 / dCount) /
- 60, (sum5 / dCount) % 60);
- fclose(outf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement