-
Notifications
You must be signed in to change notification settings - Fork 0
/
testinglagi.c
114 lines (104 loc) · 2.55 KB
/
testinglagi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
void go_fibonacci(int number, int counter, int t1, int t2, char word[1001], int mode);
int main()
{
int t, j, k ;
int key_word[15], fibo_number[15];
char m[15][1001];
int condition = 0;
scanf("%d", &t);
if ((t >= 1) && (t <= 15))
{
for (k = 1; k <= t; k++)
{
// key_word pake array
scanf("%d", &key_word[k]);
if ((key_word[k] >= 0 ) && (key_word[k] <= 1))
{
// fibo_number pake array
scanf("%d", &fibo_number[k]);
scanf(" %[^\n]s", m[k]);
}
else
{
printf("Mode is not valid!\n");
condition = 1;
break;
}
}
if (condition == 0)
{
for (j = 1; j <= t; j++)
{
go_fibonacci(fibo_number[j], 3, 1, 1, m[j], key_word[j]);
printf("\n");
}
}
}
else
{
printf("Mode is not valid!\n");
}
return 0;
}
void go_fibonacci(int number, int counter, int t1, int t2, char word[1001], int mode)
{
int nextTerm, WordLength, k, AddNum, ascii;
int num_result;
if (number == 1)
{
printf("%d ", t1);
}
if (number == 2)
{
printf("%d ", t2);
}
if ((number >= 3) && (number >= counter))
{
nextTerm = t1 + t2 ;
t1 = t2;
t2 = nextTerm;
go_fibonacci(number, counter+1, t1, t2, word, mode);
}
if (number == counter)
{
WordLength = strlen(word);
AddNum = nextTerm % 26;
for( k=0 ; k < WordLength; k++)
{
ascii = (int) word[k];
if (ascii != 32)
{
if (mode == 0)
{
num_result = ascii + AddNum;
if (num_result > 122)
{
num_result = num_result - 26;
}
if (num_result < 97)
{
num_result = num_result + 26;
}
}
else
{
num_result = ascii - AddNum;
if (num_result > 122)
{
num_result = num_result - 26;
}
if (num_result < 97)
{
num_result = num_result + 26;
}
}
}
printf("%c", num_result);
}
}
}