Skip to content
Open
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
69 changes: 69 additions & 0 deletions dz8
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <stdlib.h>
#define N 1000

bool Condition1(char *s); //перевіряє, що рядок починається з деякої ненульової цифри, за якою знаходяться тільки літери і їх кількість дорівнює числовому значенню цієї цифри
bool Condotion2(char *s); //перевіряє, що рядок складається тільки з цифр, причому їх числові значення складають арифметичну прогресію
int main()
{
char s[N];
printf("Input string : ");
fgets(s, N, stdin);
printf("%d\n", Condition1(s));
char s1[N];
printf("Input string : ");
fgets(s1, N, stdin);
printf("%d\n", Condotion2(s1));
}

bool Condition1(char *s)
{
bool b = true;
int x = 0;
if( isdigit(s[0]) && (strlen(s) - 2) == atoi(&s[0]))
{
for(int i = 1; (i <= strlen(s) - 2) && b; i++)
{
if(isalpha(s[i])){x++;}
}
}
if( x == strlen(s) - 2) {b = true;}
else {b = false;}
return b;
}

bool Condotion2(char *s)
{
bool b = false;
int x = strlen(s) - 1;
int y = 0;
int n = 0;
char st[x];
for(int i = 0; i < x; i++)
{
if(isdigit(s[i]) || s[i] == ' '){
b = true;
}
if(isdigit(s[i]) && b)
{
st[n] = atoi(&s[i]);
n++;
}
}
if (b)
{
y = st[1] - st[0];
for(int i = 1; i < n - 1 ; i++)
{
if(st[i+1] - st[i] != y)
{
b = false;
break;
}
}
}
return b;
}