/**
* @file main.c
* @author Мосяж А.М., гр. 515б
* @date 26 квітня 2023
* @brief Лабораторна робота № 3, варіант 4
* Робота з масивами Завдання 1
*/
#include <stdio.h>
#include <locale.h>
#include "func.h"
int main()
{
long n;
int digit_seen[10] = { 0 };
setlocale(LC_ALL, "Ukr");
printf("Введiть число: ");
scanf("%ld", &n);
count_repeated_digits(n, digit_seen);
print_repited_digits(digit_seen);
return 0;
}
#include <stdio.h>
#include <locale.h>
void count_repeated_digits(long long n, int* digits)
{
int digit;
while (n > 0)
{
digit = n % 10;
digits[digit]++;
n /= 10;
}
return;
}
void print_repited_digits(int* digits)
{
printf("цифра\tкiлькiсть\n");
for (int i = 0;i < 10;i++)
if (digits[i])
printf("%d\t%d\n", i, digits[i]);
}
void count_repeated_digits(long long n, int* digits);
void print_repited_digits(int* digits);
#include "pch.h"
#include "pch.h"
#include "\3003\func.c"
#include <gtest/gtest.h>
TEST(CountRepeatedDigitsTest, Test1)
{
int digits[10] = { 0 };
long long n = 1234507890;
count_repeated_digits(n, digits);
EXPECT_EQ(digits[0], 2);
EXPECT_EQ(digits[1], 1);
EXPECT_EQ(digits[2], 1);
EXPECT_EQ(digits[3], 1);
EXPECT_EQ(digits[4], 1);
EXPECT_EQ(digits[5], 1);
EXPECT_EQ(digits[6], 0);
EXPECT_EQ(digits[7], 1);
EXPECT_EQ(digits[8], 1);
EXPECT_EQ(digits[9], 1);
}
TEST(CountRepeatedDigitsTest, Test2)
{
int digits[10] = { 0 };
long long n = 3453636345334;
count_repeated_digits(n, digits);
EXPECT_EQ(digits[0], 0);
EXPECT_EQ(digits[1], 0);
EXPECT_EQ(digits[2], 0);
EXPECT_EQ(digits[3], 6);
EXPECT_EQ(digits[4], 3);
EXPECT_EQ(digits[5], 2);
EXPECT_EQ(digits[6], 2);
EXPECT_EQ(digits[7], 0);
EXPECT_EQ(digits[8], 0);
EXPECT_EQ(digits[9], 0);
}
TEST(CountRepeatedDigitsTest, Test3)
{
int digits[10] = { 0 };
long long n = 337333322555575;
count_repeated_digits(n, digits);
EXPECT_EQ(digits[0], 0);
EXPECT_EQ(digits[1], 0);
EXPECT_EQ(digits[2], 2);
EXPECT_EQ(digits[3], 6);
EXPECT_EQ(digits[4], 0);
EXPECT_EQ(digits[5], 5);
EXPECT_EQ(digits[6], 0);
EXPECT_EQ(digits[7], 2);
EXPECT_EQ(digits[8], 0);
EXPECT_EQ(digits[9], 0);
}
TEST(CountRepeatedDigitsTest, Test4)
{
int digits[10] = { 0 };
long long n = 4412312312312344;
count_repeated_digits(n, digits);
EXPECT_EQ(digits[0], 0);
EXPECT_EQ(digits[1], 4);
EXPECT_EQ(digits[2], 4);
EXPECT_EQ(digits[3], 4);
EXPECT_EQ(digits[4], 4);
EXPECT_EQ(digits[5], 0);
EXPECT_EQ(digits[6], 0);
EXPECT_EQ(digits[7], 0);
EXPECT_EQ(digits[8], 0);
EXPECT_EQ(digits[9], 0);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}