Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
#include <iostream>
#include <string>
#include <math.h>

#include<cassert>
using namespace std;

long long *b;
//long long int* m;
void test_factorial();

long long int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}

long long int *producingTheFactorialFractions()
long long int* producingTheFactorialFractions()
{
long long b[10];

for (int i = 10; i >= 0; i--)
{
b[i] += (int)pow(factorial(10), 2.0) / (i + 1);
long long int b[10] = { 0 };
//int i = 10
long long int m;
for (int i = 9; i >= 0; i--)
{ //(int)
m = (long long int)pow(factorial(10), 2.0);
b[i] += (long long int)pow(factorial(10), 2.0) / (i + 1);
}
return b;
}

void checkZeros(long long *a)
void checkZeros(long long int a[10])
{
for (int i = 9; i >= 0; i--)
{
if (a[i] = 0)
{ //a[i] = 0
if (a[0] == 0)
cout << "Zero Found" << endl;
}
}

int main()
{

long long int *a;
long long int* a;
//
a = new long long int[10];
a = producingTheFactorialFractions();
checkZeros(a);

long long int a2[10];
for (int i = 0; i < 10; i++)
{
cout << a[i] << endl;
}
delete a;
a2[i] = a[i];

cout<<"hello";
cout<<"Bye";
checkZeros(a2);

for (int i = 0; i < 10; i++)
{
cout << a2[i] << endl;
}
//delete[] a;
}

}
void test_factorial()
{
long long int a = factorial(10);
assert(a == 3628800);
}
12 changes: 8 additions & 4 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ using namespace std;

// count all the specific char in the whole array of strings
int countAllSpecificChars(string sArr[], int arrLength, char specificChar) {
int count;
for (int i = 0; i <= arrLength; ++i)
for (int j = 0; j <= sArr[i].size(); ++j)
//int count;
int count = 0;
//i <= arrLength
for (int i = 0; i < arrLength; ++i)
// j <= sArr[i].size()
for (int j = 0; j < sArr[i].size(); ++j)
// if the jth char of the string is the specific char
if (sArr[i][j] = specificChar)
//sArr[i][j] = specificChar
if (sArr[i][j] == specificChar)
count++;
return count;
}
Expand Down
69 changes: 55 additions & 14 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
#define MAX_SIZE 200
int arr[MAX_SIZE];
//int arr[MAX_SIZE];
long long arr[MAX_SIZE];

typedef struct alfa * alfaptr;

typedef struct alfa* alfaptr;

struct alfa {
long long x;
alfaptr next;
};
alfaptr rear = NULL, front = NULL;
void push(int x)

//int x
void push(long long x)
{
alfaptr node;
node = (alfaptr)malloc(sizeof(struct alfa));
node->x = x;
//
node->next = NULL;
if (!front)
{
front = node;
//
rear = node;
}
else {
rear->next = node;
rear = node;
Expand All @@ -25,33 +36,57 @@ void push(int x)

void pop()
{
alfaptr node;
if (!front)
printf("ERROR1");
else
{
node = front->next;
front = node;
//
alfaptr node = front;
//node = front->next;
//front = node;
//
front = node->next;
free(node);
}
}
void search(int x)

//int
void search(long long x)
{
alfaptr node = front;
int counter = 0;
while (node)
//{}
{
if (node->x == x)
{
//
counter++;
printf("%d", counter);
}
else {
printf("ERROR2");
break;
//break;
}
node = node->next;
}
}

void rpop() {//pop last element

//
if (front == rear)
{
front = NULL;
rear = NULL;
return;
}
alfaptr node = front;
while (node)
//node
while (node->next != rear)
node = node->next;
//
node->next = NULL;
free(rear);
rear = node;
}
Expand All @@ -66,29 +101,35 @@ void set()
int size()
{
alfaptr node = front;
int count;
//count
int count = 0;
while (node)
count++;node = node->next;
{
count++;
node = node->next;
}
return count;
}

void show()
{
if (!front) {
for (int i = 0; i < MAX_SIZE; i++)
printf("%d ", arr[i]);
printf("%lld ", arr[i]);
}
else
{
printf("ERROR3");
}
}

int average()
//long long
long long average()
{

alfaptr node = front;
int sum = 0, count;
//int //count
long long sum = 0, count = 0;
while (node) {
sum += node->x;
count++;
Expand Down