#include <stdio.h>
#include <sys/time.h>

int f(int d)
{
	int k;
	int n;                      // 桁数
	int zero;                   // ゼロ個数
	int res;                    // 結果

	// 桁数数えなど
	k = 1;
	for (n = 0; d > k; n++) {
		k *= 10;
	}
	// 0以外をresにいれながら0を数える
	res = zero = 0;
	for (; n > 0; n--) {
		k /= 10;
		if (d >= k) {
			res = res * 10 + d / k;
		}
		else {
			zero++;
		}
		d %= k;
	}

	// 0を付け加える
	for (; zero > 0; zero--) {
		res *= 10;
	}

	// 終了
	return res;

}

int main()
{
	int v = 20010307;           // 値
	//int v = 1020304050;         // 値
	int ex = 100000;            // 実行回数
	int count = 222;            // 計測回数
	int res;
	int i, j;
	struct timeval s, e;
	double sum=0;                 // 結果

	printf("f(%d);を%d回実行する時間の計測を%d回し、平均時間を出す\n", v, ex, count);
	sum = 0.0;
	for (j = 0; j < count; j++) {
		gettimeofday(&s, NULL);
		for (i = 0; i < ex; i++) {
			res = f(v);
		}
		gettimeofday(&e, NULL);
		sum += (e.tv_sec - s.tv_sec) + (e.tv_usec - s.tv_usec) / 1000000.0;
	}
	printf("result = %d, time = %fms\n", res, 1000.0 * sum / ((double)count));
	return 0;
}