Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // eh.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <random>
- #include <time.h>
- int _tmain(int argc, _TCHAR* argv[])
- {
- clock_t begin, end;
- clock_t petla_begin, petla_end;
- double time_spent = 0;
- double total_time = 0;
- //total_time += time_spent;
- bool a = true;
- int len_a = 0;
- int len_b = 0;
- int n = 0;
- char str_a[1000];
- char str_b[1000];
- char* str_c;
- int ch, lastch = '\0';
- begin = clock();
- while ((ch = getchar()) != EOF)
- {
- if (ch == 10)
- {
- a = !a;
- str_c = (char *)malloc(sizeof(char) * (len_a + len_b + 3));
- //strcat(str_c, str_a);
- strncpy(str_c, str_a, len_a);
- //strcat(str_c, str_b);
- strncpy(str_c + len_a, str_b, len_b);
- //str_c[len_a + len_b] = '\0';
- n++;
- free(str_c);
- len_a = 0;
- len_b = 0;
- }
- else if (ch == 32)
- {
- a = !a;
- }
- else
- {
- if (a)
- {
- str_a[len_a] = ch;
- len_a++;
- }
- else
- {
- str_b[len_b] = ch;
- len_b++;
- }
- }
- }
- end = clock();
- petla_begin = clock();
- long ij = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < 1000; j++)
- {
- ij++;
- }
- }
- petla_end = clock();
- time_spent = (double)(end - begin) - (double)(petla_end-petla_begin);
- time_spent = time_spent / CLOCKS_PER_SEC;
- printf("total time: %.50f\n", time_spent);
- printf("avg: %.50f\n", time_spent / n);
- return (int)ij;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement