Long time no see

This commit is contained in:
2026-02-21 10:47:00 +07:00
parent 0d54fe176e
commit b7df98a55c
198 changed files with 3249 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
void inc(int *p){(*p)++;}
void dec(int *p){(*p)--;}
int main(){
int x=10;
inc(&x);
dec(&x);
return 0;
}
+350
View File
@@ -0,0 +1,350 @@
# Генерация и анализ ассемблерного кода программы на C
---
## main.c
```c
void inc(int *p){(*p)++;}
void dec(int *p){(*p)--;}
int main(){
int x=10;
inc(&x);
dec(&x);
return 0;
}
```
---
## linux_x86_64_numbered.s
```asm
1 .file "main.c"
2 .text
3 .globl inc
4 .type inc, @function
5 inc:
6 .LFB0:
7 .cfi_startproc
8 pushq %rbp
9 .cfi_def_cfa_offset 16
10 .cfi_offset 6, -16
11 movq %rsp, %rbp
12 .cfi_def_cfa_register 6
13 movq %rdi, -8(%rbp)
14 movq -8(%rbp), %rax
15 movl (%rax), %eax
16 leal 1(%rax), %edx
17 movq -8(%rbp), %rax
18 movl %edx, (%rax)
19 nop
20 popq %rbp
21 .cfi_def_cfa 7, 8
22 ret
23 .cfi_endproc
24 .LFE0:
25 .size inc, .-inc
26 .globl dec
27 .type dec, @function
28 dec:
29 .LFB1:
30 .cfi_startproc
31 pushq %rbp
32 .cfi_def_cfa_offset 16
33 .cfi_offset 6, -16
34 movq %rsp, %rbp
35 .cfi_def_cfa_register 6
36 movq %rdi, -8(%rbp)
37 movq -8(%rbp), %rax
38 movl (%rax), %eax
39 leal -1(%rax), %edx
40 movq -8(%rbp), %rax
41 movl %edx, (%rax)
42 nop
43 popq %rbp
44 .cfi_def_cfa 7, 8
45 ret
46 .cfi_endproc
47 .LFE1:
48 .size dec, .-dec
49 .globl main
50 .type main, @function
51 main:
52 .LFB2:
53 .cfi_startproc
54 pushq %rbp
55 .cfi_def_cfa_offset 16
56 .cfi_offset 6, -16
57 movq %rsp, %rbp
58 .cfi_def_cfa_register 6
59 subq $16, %rsp
60 movq %fs:40, %rax
61 movq %rax, -8(%rbp)
62 xorl %eax, %eax
63 movl $10, -12(%rbp)
64 leaq -12(%rbp), %rax
65 movq %rax, %rdi
66 call inc
67 leaq -12(%rbp), %rax
68 movq %rax, %rdi
69 call dec
70 movl $0, %eax
71 movq -8(%rbp), %rdx
72 subq %fs:40, %rdx
73 je .L5
74 call __stack_chk_fail@PLT
75 .L5:
76 leave
77 .cfi_def_cfa 7, 8
78 ret
79 .cfi_endproc
80 .LFE2:
81 .size main, .-main
82 .ident "GCC: (GNU) 15.2.1 20251112"
83 .section .note.GNU-stack,"",@progbits
```
---
# windows_x86_64_numbered.s
```asm
1 .file "main.c"
2 .text
3 .globl inc
4 .def inc; .scl 2; .type 32; .endef
5 .seh_proc inc
6 inc:
7 pushq %rbp
8 .seh_pushreg %rbp
9 movq %rsp, %rbp
10 .seh_setframe %rbp, 0
11 .seh_endprologue
12 movq %rcx, 16(%rbp)
13 movq 16(%rbp), %rax
14 movl (%rax), %eax
15 leal 1(%rax), %edx
16 movq 16(%rbp), %rax
17 movl %edx, (%rax)
18 nop
19 popq %rbp
20 ret
21 .seh_endproc
22 .globl dec
23 .def dec; .scl 2; .type 32; .endef
24 .seh_proc dec
25 dec:
26 pushq %rbp
27 .seh_pushreg %rbp
28 movq %rsp, %rbp
29 .seh_setframe %rbp, 0
30 .seh_endprologue
31 movq %rcx, 16(%rbp)
32 movq 16(%rbp), %rax
33 movl (%rax), %eax
34 leal -1(%rax), %edx
35 movq 16(%rbp), %rax
36 movl %edx, (%rax)
37 nop
38 popq %rbp
39 ret
40 .seh_endproc
41 .globl main
42 .def main; .scl 2; .type 32; .endef
43 .seh_proc main
44 main:
45 pushq %rbp
46 .seh_pushreg %rbp
47 movq %rsp, %rbp
48 .seh_setframe %rbp, 0
49 subq $48, %rsp
50 .seh_stackalloc 48
51 .seh_endprologue
52 call __main
53 movl $10, -4(%rbp)
54 leaq -4(%rbp), %rax
55 movq %rax, %rcx
56 call inc
57 leaq -4(%rbp), %rax
58 movq %rax, %rcx
59 call dec
60 movl $0, %eax
61 addq $48, %rsp
62 popq %rbp
63 ret
64 .seh_endproc
65 .def __main; .scl 2; .type 32; .endef
66 .ident "GCC: (GNU) 15.2.0"
```
---
# riscv64_numbered.s
```asm
1 .file "main.c"
2 .option pic
3 .attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zmmul1p0_zaamo1p0_zalrsc1p0_zca1p0_zcd1p0"
4 .attribute unaligned_access, 0
5 .attribute stack_align, 16
6 .text
7 .align 1
8 .globl inc
9 .type inc, @function
10 inc:
11 .LFB0:
12 .cfi_startproc
13 addi sp,sp,-32
14 .cfi_def_cfa_offset 32
15 sd ra,24(sp)
16 sd s0,16(sp)
17 .cfi_offset 1, -8
18 .cfi_offset 8, -16
19 addi s0,sp,32
20 .cfi_def_cfa 8, 0
21 sd a0,-24(s0)
22 ld a5,-24(s0)
23 lw a5,0(a5)
24 addiw a5,a5,1
25 sext.w a4,a5
26 ld a5,-24(s0)
27 sw a4,0(a5)
28 nop
29 ld ra,24(sp)
30 .cfi_restore 1
31 ld s0,16(sp)
32 .cfi_restore 8
33 .cfi_def_cfa 2, 32
34 addi sp,sp,32
35 .cfi_def_cfa_offset 0
36 jr ra
37 .cfi_endproc
38 .LFE0:
39 .size inc, .-inc
40 .align 1
41 .globl dec
42 .type dec, @function
43 dec:
44 .LFB1:
45 .cfi_startproc
46 addi sp,sp,-32
47 .cfi_def_cfa_offset 32
48 sd ra,24(sp)
49 sd s0,16(sp)
50 .cfi_offset 1, -8
51 .cfi_offset 8, -16
52 addi s0,sp,32
53 .cfi_def_cfa 8, 0
54 sd a0,-24(s0)
55 ld a5,-24(s0)
56 lw a5,0(a5)
57 addiw a5,a5,-1
58 sext.w a4,a5
59 ld a5,-24(s0)
60 sw a4,0(a5)
61 nop
62 ld ra,24(sp)
63 .cfi_restore 1
64 ld s0,16(sp)
65 .cfi_restore 8
66 .cfi_def_cfa 2, 32
67 addi sp,sp,32
68 .cfi_def_cfa_offset 0
69 jr ra
70 .cfi_endproc
71 .LFE1:
72 .size dec, .-dec
73 .align 1
74 .globl main
75 .type main, @function
76 main:
77 .LFB2:
78 .cfi_startproc
79 addi sp,sp,-32
80 .cfi_def_cfa_offset 32
81 sd ra,24(sp)
82 sd s0,16(sp)
83 .cfi_offset 1, -8
84 .cfi_offset 8, -16
85 addi s0,sp,32
86 .cfi_def_cfa 8, 0
87 li a5,10
88 sw a5,-20(s0)
89 addi a5,s0,-20
90 mv a0,a5
91 call inc
92 addi a5,s0,-20
93 mv a0,a5
94 call dec
95 li a5,0
96 mv a0,a5
97 ld ra,24(sp)
98 .cfi_restore 1
99 ld s0,16(sp)
100 .cfi_restore 8
101 .cfi_def_cfa 2, 32
102 addi sp,sp,32
103 .cfi_def_cfa_offset 0
104 jr ra
105 .cfi_endproc
106 .LFE2:
107 .size main, .-main
108 .ident "GCC: (GNU) 15.1.0"
109 .section .note.GNU-stack,"",@progbits
```
---
## INFO
---
### gcc_version
gcc (GCC) 15.2.1 20251112
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
### linux_gcc_version
gcc (GCC) 15.2.1 20251112
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
### mingw_version
x86_64-w64-mingw32-gcc (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
### riscv_version
riscv64-linux-gnu-gcc (GCC) 15.1.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
### sysinfo
Linux archlinux 6.17.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 14 Nov 2025 06:54:20 +0000 x86_64 GNU/Linux
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
+92
View File
@@ -0,0 +1,92 @@
#include <stdio.h>
void pt(int prog[], int cmd,int acc,int pc);
int main() {
int prog[] = {
2, 5, // load 5
3, 3, // mult 3
1, // print acc
4, 7, // jump 7
2, 0, // load 0
5, 11,// jz 11
2, 2, // load 2
5, 1, // jz 1
3, 4, // mul 4
1, // print
0 // stop
};
int cmd, pc, acc;
cmd = pc = acc = 0;
while(pc != -1){
cmd = prog[pc];
switch(cmd){
case 0: //Проверка на команду остановки
printf("STOP\t ACC = %d\t PC = %d",acc,pc);
pc = -1;
break;
case 1: // Комманда 1 - вывод регистра
pt(prog,cmd,acc,pc);
pc++;
break;
case 2: // Комманда 2 - Присвоить регистру число
acc = prog[pc+1];// из след ячейки памяти
pt(prog,cmd,acc,pc);
pc+=2;
break;
case 3: // Комманда 3 - Умножить регистр на число
acc *= prog[pc+1];// в след ячейке памяти
pt(prog,cmd,acc,pc);
pc +=2;
break;
case 4: // Комманда 4 - Безусловный переход на указанную
pt(prog,cmd,acc,pc); // ячейку памяти
pc = prog[pc+1];
break;
case 5: // Комманда 5 - Переход на указанную ячейку
pt(prog,cmd,acc,pc);// памяти если регистр равен 0
if(acc == 0){pc = prog[pc+1];}
else(pc+=2);
break;
default: printf("err\n");return 1; // Защита от неправильной комманды
// и бесконечного зацикливания
}
}
return 0;
}
// Блок отвечающий за вывод в терминал
// значиний в момент выполнения комманд
void pt(int prog[],int cmd,int acc,int pc){
printf("\n");
printf("cmd: %d\n",cmd);
switch(cmd){
case 1:
printf("\tPrint acc\n\t\tacc = %d\n",acc);
printf("\t\tcurr pc = %d",pc);break;
case 2:
printf("\tLoad acc\n\t\tacc = %d\n",acc);
printf("\t\tcurr pc = %d",pc);break;
case 3:
printf("\tMult acc\n\t\tacc = %d\n",acc);
printf("\t\tcurr pc = %d",pc);break;
case 4:
printf("\tJump to\n\t\tto = %d\n",prog[pc+1]);
printf("\t\tcurr pc = %d",pc);break;
case 5:
if(acc==0){
printf("\tJump to if acc zero\n\t\tto = %d\n",prog[pc+1]);
}else(printf("\tJump to if acc zero\n\t\tacc != 0\n"));
printf("\t\tcurr pc = %d",pc);
break;
}
printf("\n");
}
+146
View File
@@ -0,0 +1,146 @@
#include <stdio.h>
#include <string.h>
int scan(void);
unsigned long func(int n);
void output(unsigned long sum);
void encr(unsigned long sum, char *cpum);
int cpumodel(char cpum[]);
int main() {
int n;
unsigned long isum;
char cpum[64];
cpumodel(cpum);
printf("Buff: ");
if (getchar() == '0') {
setbuf(stdin, NULL);
printf("buff is off\n");
} else {
printf("buff is on\n");
}
while(getchar()!='\n');
n = scan();
if(n == 0) return 0;
isum = func(n);
output(isum);
encr(isum,cpum);
return 0;
}
int scan(void){
int x, n;
n = 0;
printf("Enter num: 1-100 000\nNum: ");
while(((x = getchar())!='\n') && x != EOF){
if((x >= '0') && (x <= '9')){
n = (n*10) + (x-'0');
}
else{
if(x == '\n');
else(printf("Err \"%c\" is not a num.\n",x));
while((x = getchar())!='\n')
if(x == EOF) return 0;
printf("Num: ");
n = 0;
continue;
}
if(n > 100000){
while((x = getchar())!='\n')
if(x == EOF) return 0;
n = 0;
printf("You enter n>100 000 Try again\nNum: ");
continue;
}
if(x=='0'&&n<=0){
while((x = getchar())!='\n')
if(x == EOF) return 0;
printf("You num cannot starts with 0. Try again\nNum: ");
continue;
}
}
if (x == EOF) return 0;
return(n);
}
unsigned long func(int n){
int i;
unsigned long sum = 0;
unsigned char mem[65536];
char data[256 * 1024];
for(i = 1; i <= n; i++){
sum += i;
mem[i%65536] = (unsigned char)(i % 256);
data[i%(256*1024)] = (unsigned char)((sum + i) % 256U);
}
return sum;
}
void output(unsigned long sum){
int i = 0;
char buf[20];
printf("\nresult: ");
while(sum > 0){
buf[i++] = (char)('0' + (sum % 10));
sum /= 10;
}
while (i-- > 0)
putchar(buf[i]);
putchar('\n');
}
int cpumodel(char cpum[]) {
int c, i = 0;
printf("\nEnter proc name: ");
while ((c = getchar()) != '\n' && c != EOF && i < 64 - 1) {
cpum[i++] = (char)c;
}
cpum[i] = '\0';
return i;
}
void encr(unsigned long sum, char *cpum) {
char buf[20];
int i = 0;
int cpu_len = strlen(cpum);
if (cpu_len == 0) {
printf("CPU model is empty!\n");
return;
}
if (sum == 0) {
buf[i++] = '0';
} else {
while (sum > 0) {
buf[i++] = '0' + (sum % 10);
sum /= 10;
}
}
printf("enc result: ");
for (int j = i - 1; j >= 0; j--) {
int digit = buf[j] - '0';
char cpu_char = cpum[(i - 1 - j) % cpu_len];
int enc = (digit + (int)cpu_char) % 10;
putchar('0' + enc);
}
putchar('\n');
}
@@ -0,0 +1 @@
AMD Ryzen 5 5600X 6-Core Processor
@@ -0,0 +1,24 @@
model name : AMD Ryzen 5 5600X 6-Core Processor
cache size : 512 KB
cpu cores : 6
MemTotal: 16293648 kB
Caches (sum of all):
L1d: 192 KiB (6 instances)
L1i: 192 KiB (6 instances)
L2: 3 MiB (6 instances)
L3: 32 MiB (1 instance)
Кэш‑память расположена близко к ядрам процессора (обычно в том же кристалле), поэтому доступ к ней происходит за несколько тактов процессора, тогда как доступ к оперативной памяти требует десятки‑сот тактов из‑за физической дистанции, шины и контроллера памяти.
Параметр Кэш L1/L2/L3 Оперативная RAM
Время доступа 1–5 такт(ов) 50–150 такт(ов)
Емкость десятки‑сот КБ несколько ГБ
Стоимость (энергия/площадь) Высокая Низкая
Ryzen 55600X
Тактовая частота ядра: ~4.6 ГГц → один такт ≈ 0.22 нс.
Время доступа к L1: ~4 такт ≈ 0.9 нс.
Время доступа к DDR4‑3200 RAM: ~70 такт ≈ 15 нс.
Если 95 % инструкций и данных находятся в кэше, среднее время доступа будет близко к 1 нс, а не к 15 нс, что делает процессор эффективным несмотря на медленную RAM.
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
HOMECPU="homecpu.txt"
CURRENTCPU=$(grep -m1 'model name' /proc/cpuinfo | awk -F':' '{print $2}' | sed -E 's/^[ \t]+//')
# Извлекаем только модель (например, i7-9700K из полного названия)
EXTRACT_MODEL() {
echo "$1" | grep -oE '[iI]ntel|[aA]md|[iI][0-9]*-[0-9A-Z]*|[rR]yzen|[0-9A-Z]*-[0-9A-Z]*' | head -1
}
CURRENT_MODEL=$(EXTRACT_MODEL "$CURRENTCPU")
gcc ./code.c -o ./run
if [ ! -f "$HOMECPU" ]; then
echo "Домашняя модель CPU не найдена, используем текущую: $CURRENT_MODEL"
CPUMODEL="$CURRENT_MODEL"
else
HOMECPU_CONTENT=$(<"$HOMECPU")
HOME_MODEL=$(EXTRACT_MODEL "$HOMECPU_CONTENT")
echo "Домашняя модель CPU: $HOME_MODEL"
echo "Текущая модель CPU: $CURRENT_MODEL"
if [ "$CURRENT_MODEL" = "$HOME_MODEL" ]; then
echo "Модели совпадают, используем текущую модель"
CPUMODEL="$CURRENT_MODEL"
else
echo "Модели не совпадают, используем домашнюю модель"
CPUMODEL="$HOME_MODEL"
fi
fi
# Отправляем модель CPU и ввод для программы
( printf "%s\n1\n" "$CPUMODEL"; cat ) | ./run
+1
View File
@@ -0,0 +1 @@
15
+22
View File
@@ -0,0 +1,22 @@
global_var = 10
neg_num = -5
result = global_var + neg_num
user_age = int(input())
if global_var >= 5:
result = result + 1
if neg_num <= 0:
print("Negatine num\n")
counter = 0
while counter <= 3:
print(counter)
counter += 1
for i in range(10):
result = result + 1
print(result)
print(user_age)
+317
View File
@@ -0,0 +1,317 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#define MAXINPUTARRAY 1000
#define MAXKNOWN 30
#define MAXROW 40
#define CMDLIST 4
#define CMDCOUNT 6
int it_is_what(wchar_t ch);
int main(){
setlocale(LC_ALL, "");
wchar_t massive[MAXINPUTARRAY] = {0};
wchar_t knownint[MAXKNOWN] = {0};
int CellsInMainArray = 0;
{ // GET ALL INPUT
wchar_t ch;
while((ch = getwchar()) != WEOF){
massive[CellsInMainArray]=ch;
CellsInMainArray++;
if(CellsInMainArray>=MAXINPUTARRAY)
return 1100;
}
}
{ // IS X(LETTER) EXISIST?
int k = 0;
while(k++ < CellsInMainArray){
if((massive[k] >= 'a' && massive[k] <= 'z') &&
massive[k+1]==' ' &&
!(massive[k-1] >= 'a' && massive[k-1] <= 'z')){
int mark = 1;
for(int i = 0;i<MAXKNOWN-1;i++){
if(massive[k]==knownint[i])mark=0;
}
if(mark){
putwchar(L'i'); putwchar(L'n');
putwchar(L't');putwchar(L' ');
putwchar(massive[k]); putwchar(' ');
putwchar('='); putwchar(' ');
putwchar('0'); putwchar(';'); putwchar('\n');
knownint[knownint[MAXKNOWN-1]] = massive[k];knownint[MAXKNOWN-1]++;
}
}
}
putwchar('\n');putwchar('\n');
}
int massiveCursor = 0;
wchar_t row[MAXROW] = {0};
int deathMark = 1;
do{
int command = 0;
int rowCursor = 0;
{// GET ROW
{ // CLEAR ROW
for(int i=0; i<MAXROW; i++) row[i] = ' ';
rowCursor = 0;
}
{ // GET ROW
while(massiveCursor < CellsInMainArray && rowCursor < MAXROW &&
massive[massiveCursor] != '\n' && row[rowCursor] != WEOF){
row[rowCursor] = massive[massiveCursor];
massiveCursor++;
rowCursor++;
if(massive[massiveCursor] == '\0' ||
massive[massiveCursor] == WEOF){
deathMark = 0;
}
}
massiveCursor++;
rowCursor++;
}
if(massiveCursor>MAXINPUTARRAY)return 0;
}
{ // TEST FOR COMMENT AND \t \n ' '
{
if(row[0]=='#'){
int i = 0;
putwchar('/');putwchar('/');
while(i++ < rowCursor)putwchar(row[i]);
putwchar('\n');
continue;
}
}
{
int i = 0;
if(row[0] == WEOF) return 0;
if(rowCursor<4){
while(i < rowCursor) putwchar(row[i++]);
continue;}
}
{
while(row[0]=='\t' || row[0] == ' '){
putwchar(row[0]);
for(int i = 0;i<rowCursor;i++){
row[i]=row[i+1];
}
rowCursor--;
}
}
}
{ //Test for see what command is it
wchar_t cmd[CMDLIST][CMDCOUNT] = {L"if",L"while",L"for",L"print"};
for(int i = 0;i<CMDLIST;i++){
int marker = 0;
int symbCount = 0;
for(int k = 0;cmd[i][k]!='\0';k++){
symbCount++;
}
for(int k = 0;k < symbCount;k++){
if(row[k]==cmd[i][k]){
marker++;
}
if (symbCount == marker && symbCount != 0){
command = i+1;
break;
}
}
if(command!= 0) break;
}
}
{//PRINT x = something;
if(it_is_what(row[0])==0 && // Enter if its letter
(it_is_what(row[2])==8 || // and logic
it_is_what(row[2])==9)){ // or arfimetic
wchar_t pyinput[] = L"int(input())";
int marker = 1,i=0;
while(pyinput[i++]!='\0'){
if(row[i+4]!=pyinput[i])marker=0;
}
if(marker){
wchar_t cinput[] = {L"scanf(\"%d\", &"};
i = 0;
while(cinput[i]!='\0')
putwchar(cinput[i++]);
putwchar(row[0]);putwchar(')');putwchar(';');putwchar('\n');
}
else{
for(int i = 0;i<rowCursor;i++){
if(row[i]=='\n')row[i]='\0';
putwchar(row[i]);
}
putwchar(';');putwchar('\n');
}
continue;
}
}
switch(command){ //COMMANDS
case 1:{ // IF if x > 0:
{ // PRINT PRE LETTERS
wchar_t word[] = L"if(";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
{ // IF FUNC
int xpos = 3;
putwchar(row[xpos]);// x
putwchar(row[xpos+2]);// >
// >=
int tmp = 0;
if(it_is_what(row[xpos+3])==8){putwchar(row[xpos+3]);tmp++;}
// NUM
for(int i = xpos+4+tmp;i<rowCursor;i++){
if(it_is_what(row[i])==2) putwchar(row[i]);
}
}
{ // PRINT POST LETTERS
wchar_t word[] = L")\n";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
break;
} // if(x > 0)
case 2:{ // WHILE while i < 10:
{ // PRINT PRE LETTERS
wchar_t word[] = L"while(";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
{ // WHILE FUNC
int xpos = 6;
putwchar(row[xpos]);// i
putwchar(row[xpos+2]);// >
// >=
int tmp = 0;
if(it_is_what(row[xpos+3])==8){putwchar(row[xpos+3]);tmp++;}
// NUM
for(int i = xpos+4+tmp;i<rowCursor;i++){
if(it_is_what(row[i])==2) putwchar(row[i]);
}
}
{ // PRINT POST LETTERS
wchar_t word[] = L")\n";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
break;
} // while(i < 10)
case 3:{ // FOR for i in range (10):
{ // PRINT PRE LETTERS
wchar_t word[] = L"for(int ";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
{ // FOR FUNC
int xpos = 4;
putwchar(row[xpos]);
wchar_t word[] = L" = 0;i < ";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
// NUM
for(int i = xpos+11;i<rowCursor;i++)
if(it_is_what(row[i])==2) putwchar(row[i]);
}
{ // PRINT POST LETTERS
wchar_t word[] = L";i++)\n";
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
break;
} // for(int i = 0;i<10;i++)
case 4:{ // PRINT print(L"letters")
{ // PRINT PRE LETTERS
wchar_t word[] = {L"printf(\""};
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
{ // PRINT FUNC
int xpos = 6;
if(it_is_what(row[xpos])==0){
wchar_t word[] = {L"%d\", "};
int i = 0;
while(word[i]!='\0')
putwchar(word[i++]);
putwchar(row[xpos]);
}
else{
xpos++;
while(row[xpos+1]!=')'){
if(it_is_what(row[xpos])==11)
putwchar('\\');
if(it_is_what(row[xpos])==12)
putwchar('%');
putwchar(row[xpos]);
xpos++;
}
putwchar('\"');
}
}
{ // PRINT POST LETTERS
wchar_t word[] = {L");\n"};
int i = 0;
while(word[i]!='\0')putwchar(word[i++]);
}
break;
}// printf(L"letters");
}
{ // ERROR HANDLE
if (command == 0 && row[0] != WEOF){
if(row[rowCursor]=='\n')row[rowCursor]='\0';
wchar_t err[] = L"ERROR CMD NOT FOUND!";
int k = 0;
while(err[k++]!='\0')putwchar(err[k-1]);
return 1;
}
}
}while(row[0] != WEOF && deathMark);
return 0;
}
int it_is_what(wchar_t ch){
if(ch>='a'&&ch<='z')return 0;
if(ch>='A'&&ch<='Z')return 1;
if(ch>='0'&&ch<='9')return 2;
if(ch == '=' || ch == '>' || ch == '<' || ch == '!')return 8;
if(ch == '*' || ch == '-' || ch == '+' || ch == '/')return 9;
if(ch == '\\' || ch == '\"' || ch == '\'')return 11;
if(ch == '%')return 12;
return -1;
}
+373
View File
@@ -0,0 +1,373 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#define MAXINPUTARRAY 1000
#define MAXKNOWN 30
#define MAXKNOWNSYMB 32
#define MAXROW 80
#define CMDLIST 4
// --- GLOBAL DATA ---
wchar_t G_knownint[MAXKNOWN][MAXKNOWNSYMB] = {0};
int G_knownCount = 0;
// --- FUNCTION DECLARATIONS ---
int it_is_what(wchar_t ch);
int are_strings_equal(const wchar_t *s1, const wchar_t *s2);
int is_variable_known(const wchar_t *name);
void put_wchar_string(const wchar_t *s);
void put_char_string(const char *s);
// --- MAIN TRANSLATOR LOGIC ---
int main() {
setlocale(LC_ALL, "");
wchar_t massive[MAXINPUTARRAY] = {0};
int CellsInMainArray = 0;
{ // GET INPUT
wchar_t ch;
while ((ch = getwchar()) != WEOF) {
if (CellsInMainArray >= MAXINPUTARRAY) { return 1001; }
massive[CellsInMainArray++] = ch;
}
}
{ // PRE-SCAN: DECLARE ALL VARIABLES AS INT
put_char_string("#include <stdio.h>\n");
put_char_string("int main(){\n");
int k = 0;
while (k < CellsInMainArray) {
if (it_is_what(massive[k]) == 0 || it_is_what(massive[k]) == 1) {
wchar_t tempName[MAXKNOWNSYMB] = {0};
int len = 0;
int startK = k;
{ // EXTRACT NAME
while (startK < CellsInMainArray && (it_is_what(massive[startK]) >= 0)) {
if (len < MAXKNOWNSYMB - 1) tempName[len++] = massive[startK];
startK++;
}
}
{ // CHECK KEYWORDS AND DECLARE
int isKeyword = 0;
if (are_strings_equal(tempName, L"if") || are_strings_equal(tempName, L"while") ||
are_strings_equal(tempName, L"for") || are_strings_equal(tempName, L"print") ||
are_strings_equal(tempName, L"in") || are_strings_equal(tempName, L"range") ||
are_strings_equal(tempName, L"int") || are_strings_equal(tempName, L"input")) isKeyword = 1;
if (!isKeyword && tempName[0] != L'\0') {
if (!is_variable_known(tempName) && G_knownCount < MAXKNOWN) {
for (int c = 0; c < len; c++) G_knownint[G_knownCount][c] = tempName[c];
G_knownCount++;
// DECLARE VARIABLE
put_char_string("int ");
put_wchar_string(tempName);
put_char_string(" = 0;\n");
}
}
}
k = startK;
} else {
k++;
}
}
putwchar(L'\n');
}
// --- SECOND PASS: LEXICAL ANALYSIS AND TRANSLATION ---
int massiveCursor = 0;
wchar_t row[MAXROW] = {0};
int deathMark = 1;
int blockLevel = 0;
do {
if (massiveCursor >= CellsInMainArray) break;
int command = 0;
int rowCursor = 0;
int initialSpaceCount = 0;
{ // GET ROW AND INDENTATION
for (int i = 0; i < MAXROW; i++) row[i] = 0;
rowCursor = 0;
while (massiveCursor < CellsInMainArray && rowCursor < MAXROW - 1) {
wchar_t cur = massive[massiveCursor];
if (cur == L'\n') { massiveCursor++; break; }
if (cur == WEOF || massiveCursor == CellsInMainArray - 1) { deathMark = 0; }
row[rowCursor++] = cur;
massiveCursor++;
}
int i = 0;
while (row[i] == L' ' || row[i] == L'\t') { initialSpaceCount++; i++; }
// CLOSE BLOCK
if (blockLevel == 1 && initialSpaceCount == 0 && rowCursor > 0) {
put_char_string("}\n");
blockLevel = 0;
}
// PRINT INDENTATION
for (int j = 0; j < initialSpaceCount; j++) putwchar(L' ');
// TRIM ROW
if (initialSpaceCount > 0) {
for (int j = 0; j < rowCursor - initialSpaceCount; j++) {
row[j] = row[j + initialSpaceCount];
}
rowCursor -= initialSpaceCount;
for (int j = rowCursor; j < MAXROW; j++) row[j] = 0;
}
}
{ // HANDLE PYTHON COMMENTS (#)
int hashPos = -1;
for (int i = 0; i < rowCursor; i++) {
if (row[i] == L'#') { hashPos = i; break; }
}
if (hashPos != -1) {
put_char_string("//");
for (int k = 0; k < rowCursor; k++) {
if (row[k] == L'#') break;
putwchar(row[k]);
}
for (int k = hashPos + 1; k < rowCursor; k++) putwchar(row[k]);
putwchar(L'\n');
continue;
}
}
// SKIP EMPTY LINES
if (rowCursor == 0) {
putwchar(L'\n');
continue;
}
{ // DETERMINE COMMAND TYPE
wchar_t cmd_list[CMDLIST][10] = {L"if", L"while", L"for", L"print"};
for (int i = 0; i < CMDLIST; i++) {
int lenCmd = 0;
while (cmd_list[i][lenCmd] != L'\0') lenCmd++;
if (rowCursor >= lenCmd) {
int match = 1;
for (int k = 0; k < lenCmd; k++) {
if (row[k] != cmd_list[i][k]) { match = 0; break; }
}
if (match) {
int pos = lenCmd;
while(row[pos] == L' ') pos++;
if (i == 3) { // PRINT
if (row[pos] == L'(') { command = 4; break; }
} else { // IF, WHILE, FOR
int colonPos = -1;
for (int p = pos; p < rowCursor; p++) {
if (row[p] == L':') { colonPos = p; break; }
}
if (colonPos != -1) { command = i + 1; break; }
}
}
}
}
}
{ // HANDLE ASSIGNMENT / OPERATION (command == 0)
if (command == 0) {
int eqPos = -1;
int plusEqPos = -1;
int varNameEnd = -1;
for (int i = 0; i < rowCursor; i++) {
if (row[i] == L'=') {
eqPos = i;
if (i > 0 && row[i - 1] == L'+') plusEqPos = i;
varNameEnd = i - 1;
while(varNameEnd >= 0 && row[varNameEnd] == L' ') varNameEnd--;
break;
}
}
// If assignment found and not comparison
if (eqPos > 0 && row[eqPos + 1] != L'=' && plusEqPos == -1) {
// 1. Check for input pattern
wchar_t inputPattern[] = L"int(input())";
int isInput = 1;
int checkIdx = 0;
int valPos = eqPos + 1;
while (row[valPos] == L' ') valPos++;
while (inputPattern[checkIdx] != L'\0') {
if (row[valPos + checkIdx] != inputPattern[checkIdx]) { isInput = 0; break; }
checkIdx++;
}
if (isInput) {
// INPUT (scanf)
put_char_string("scanf(\"%d\", &");
for (int j = 0; j <= varNameEnd; j++) putwchar(row[j]);
put_char_string(");\n");
} else {
// REGULAR ASSIGNMENT (x = -5, x = a + 1)
for (int i = 0; i < rowCursor; i++) { putwchar(row[i]); }
put_char_string(";\n");
}
continue;
}
// Augmented Assignment (x += 1) or other unknown lines
for (int i = 0; i < rowCursor; i++) { putwchar(row[i]); }
put_char_string(";\n");
continue;
}
}
{ // TRANSLATE COMMAND (switch)
switch (command) {
case 1: // IF
case 2: // WHILE
case 3: { // FOR
wchar_t *start_word;
int len_cmd;
if (command == 1) { start_word = L"if("; len_cmd = 2; }
else if (command == 2) { start_word = L"while("; len_cmd = 5; }
else { start_word = L"for("; len_cmd = 3; }
put_wchar_string(start_word);
int pos = len_cmd;
while (row[pos] == L' ') pos++;
if (command == 3) { // FOR (i in range(10))
wchar_t iterVar[MAXKNOWNSYMB] = {0};
int ivLen = 0;
// GET ITERATOR NAME
while (row[pos] != L' ' && row[pos] != L'\0' && pos < rowCursor && row[pos] != L':') {
iterVar[ivLen++] = row[pos];
pos++;
}
// SKIP 'in range'
while (pos < rowCursor && row[pos] != L'(') pos++;
pos++;
// C FORMAT: for(i = 0; i < limit; i++)
put_wchar_string(iterVar); put_char_string(" = 0;");
put_wchar_string(iterVar); put_char_string(" < ");
// GET LIMIT
while (pos < rowCursor && row[pos] != L')' && row[pos] != L':') { putwchar(row[pos++]); }
put_char_string(";");
put_wchar_string(iterVar); put_char_string("++");
} else {
// IF / WHILE CONDITION (Handling x >= y conditions)
while (pos < rowCursor && row[pos] != L':') {
if (row[pos] == L'>' && row[pos+1] == L'=') {
put_char_string(" >= ");
pos += 2;
} else if (row[pos] == L'<' && row[pos+1] == L'=') {
put_char_string(" <= ");
pos += 2;
} else if (row[pos] == L'!' && row[pos+1] == L'=') {
put_char_string(" != ");
pos += 2;
} else if (row[pos] == L'=' && row[pos+1] == L'=') {
put_char_string(" == ");
pos += 2;
} else {
putwchar(row[pos++]);
}
}
}
put_char_string(")\n");
// OPEN BLOCK
put_char_string("{\n");
blockLevel = 1;
break;
}
case 4: { // PRINT (print(x) or print("hello"))
put_char_string("printf(");
int pos = 5;
while (row[pos] != L'(') pos++;
pos++;
int isString = (row[pos] == L'\"');
if (isString) {
putwchar(L'\"');
pos++;
while (pos < rowCursor && row[pos] != L')') {
if (row[pos] == L'\"' && isString) break;
putwchar(row[pos++]);
}
putwchar(L'\"');
} else {
put_char_string("\"%d\", ");
while (pos < rowCursor && row[pos] != L')') {
putwchar(row[pos++]);
}
}
put_char_string(");\n");
break;
}
}
}
} while (deathMark);
{ // FINAL BRACKETS
if (blockLevel == 1) {
put_char_string("}\n");
}
put_char_string("}\n");
}
return 0;
}
// --- AUXILIARY FUNCTION DEFINITIONS ---
void put_wchar_string(const wchar_t *s) {
int i = 0;
while (s[i] != L'\0') { putwchar(s[i++]); }
}
void put_char_string(const char *s) {
int i = 0;
while (s[i] != '\0') { putwchar(s[i++]); }
}
int it_is_what(wchar_t ch) {
if (ch >= L'a' && ch <= L'z') return 0;
if (ch >= L'A' && ch <= L'Z') return 1;
if (ch >= L'0' && ch <= L'9') return 2;
if (ch == L'_') return 3;
return -1;
}
int are_strings_equal(const wchar_t *s1, const wchar_t *s2) {
int i = 0;
while (s1[i] != L'\0' || s2[i] != L'\0') {
if (s1[i] != s2[i]) return 0;
i++;
}
return 1;
}
int is_variable_known(const wchar_t *name) {
if (name[0] == L'\0') return 1;
for (int r = 0; r < G_knownCount; r++) {
if (are_strings_equal(G_knownint[r], name)) {
return 1;
}
}
return 0;
}
Binary file not shown.
+43
View File
@@ -0,0 +1,43 @@
#include <stdio.h>
int main(){
int global_var = 0;
int neg_num = 0;
int result = 0;
int user_age = 0;
int Negatine = 0;
int num = 0;
int n = 0;
int counter = 0;
int i = 0;
global_var = 10 ;
neg_num = -5 ;
result = global_var + neg_num ;
scanf("%d", &user_age);
if(global_var >= 5)
{
result = result + 1;
}
if(neg_num <= 0)
{
printf("Negatine num\n");
}
counter = 0;
while(counter <= 3)
{
printf("%d", counter);
counter += 1;
}
for(i = 0;i < 10;i++)
{
result = result + 1 ;
}
printf("%d", result);
printf("%d", user_age);
}
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
gcc ./main.c -o ./output/prog
./output/prog < ./input/test.py > output/output.c
bat ./output/output.c
gcc ./output/output.c -o ./output/output
./output/output < ./input/test.num
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+41
View File
@@ -0,0 +1,41 @@
// Разработайте функцию, выполняющую преобразование строки
//с однобайтовым двоичным числом в целое десятичное число.
#include <stdio.h>
int main(){
char input;
long long int binary = 0;
int decimal = 0;
// Input
{
printf("Input binary: ");
while((input=getchar())>='0' && input <= '1'){
binary = (binary * 10) + (input - '0');
}
if(input != '\n' && input != EOF && input != 4){
printf("Err, handle char not a 1 or 0");
return 1;
}
}
// __
// Func
int base = 1;// base = (2**n)
long long int bin = binary;
while (binary) {
int last = binary % 10;
binary = binary / 10;
decimal += last * base;
base = base * 2;
}
// __
// Output
printf("binary(%lld) = decimal(%d)",bin,decimal);
return 0;
// __
}
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
gcc -std=c99 -Wall main.c func.c -o prog
+557
View File
@@ -0,0 +1,557 @@
#include "head.h"
int queryinput(int *x, int *inquery, int *query){
setlocale(LC_ALL, "");
//INPUT-------------------------------------------------
wint_t ch;
*inquery = 0;
while((ch=getwchar())!=L'\n'&&ch!=L'\t'&&ch!=L' '&&*inquery<QUERYMAX){
*(query+*inquery)=(int)ch;
(*inquery)++;
}
//______________________________________________________
if(ch == WEOF)return -1;
//COUNT -------------------------------------------------
int c=0;
if(ch==L'\n')x[2]++;
else if(ch==L'\t')x[3]++;
else if(ch==L' ')x[4]++;
while (c < *inquery)
{
int sym = query[c];
if ((sym >= L'а' && sym <= L'я') ||
(sym >= L'А' && sym <= L'Я'))
{
x[0]++;
c++;
continue;
}
if (sym >= L'0' && sym <= L'9')
{
x[1]++;
c++;
continue;
}
if (sym > 32 && sym <= 47) {
x[sym - 28]++;
c++;
continue;
}
if (sym > 58 && sym <= 64) {
x[sym - 38]++;
c++;
continue;
}
x[33]++;
c++;
}
//________________________________________________________
return 0;
}
void func1 (char **f, int *x,int inquery, int *query){
switch(funcReturn(f[2])){
case 1://Определяет среднюю длину слова в тексте
{
if(x[32]){
x[30]/=x[31];
printf("\n\tСредняя длинна слова - %d",x[30]);
}
else{
x[30]+=inquery;
x[31]++;
}
break;
}
case 2://Подсчитывает количество слов, длина которых не превышает 5 символов.
{
if(x[32]){
printf("\n\tВсего слов <5 букв - %d",x[30]);
}
else if(inquery<5)x[30]++;
break;
}
case 3://Определяет количество букв после первого и до последнего слова.
{
if(x[31]);
else {x[30]-=x[0];x[31]=1;}
if(x[32]){x[30]+=x[0];printf("\n\tКолл-во букв после 1 и до последнего слова - %d",x[30]);}
break;
}
case 4://Удаляет первую букву каждого слова и выводит результат.
{
if(x[32]);
else
put(x,1,inquery,query);
break;
}
case 5://определяет, сколько в заданном тексте слов, начинающихся с буквы,заданной пользователем.
{
if(x[32])
printf("\n\t Слов начинающихся на %c - %d",f[4][0],x[30]);
else
if(query[0]==f[3][0])x[30]++;
break;
}
case 6://находит сумму всех цифр в введенном предложении. (если в тексте нетцифр, добавить) предусмотреть обработку шаблонов (12word, wo12rd,word12)
{
if(x[32])
printf("\n\t Найти сумму всех цифр - %d",x[31]);
else
for(int i=0;i<inquery;i++){
if(query[i]>=L'0'&&query[i]<=L'9'){
x[30]=(x[30]*100)+(query[i]-L'0');
}
}
x[31]+=x[30];
x[30]=0;
break;
}
case 7:// вставляет восклицательный знак в конце каждой строки текста.
{
if(x[32]);
else{
if(query[inquery-1]==L'\n'){
if(query[inquery-2]==L'!'||query[inquery-2]==L'?'||query[inquery-2]==L'.'||query[inquery-2]==L',')
query[inquery-2]=L'!';
else {query[inquery-1]=L'!';query[inquery]=L'\n';}
x[L'!'-28]++;inquery++;}
put(x,0,inquery,query);
}
break;
}
case 8://проверяет заканчивается ли каждая строка точкой и добавляет ее при необходимости, считает сколько точек было добавлено
{
if(x[32]);
else{
if(query[inquery-1]==L'\n'){
if(query[inquery-2]==L'!'||query[inquery-2]==L'?'||query[inquery-2]==L'.'||query[inquery-2]==L',')
query[inquery-2]=L'.';
else {query[inquery-1]=L'.';query[inquery]=L'\n';}
x[L'!'-28]++;inquery++;}
put(x,0,inquery,query);
}
break;
}
case 9://определяет сколько раз в введенной строке встречается слово,заданное пользователем.
{
if(x[32])
printf("\n\t Слово %s встречается - %d раз",f[4],x[30]);
else{
if(last(inquery,query))inquery--;
x[30]+=strquery(f[3],query);}
break;
}
case 10://подсчитывает количество букв в каждом втором слове.
{
x[34] = x[0] - x[33];
if(x[32]){
x[31]=x[33]-x[31];
printf("\n\t Сумма букв в четных словах - %d",x[31]);
}
else{
if(x[30]%2==0)
x[31]+=x[34];
x[33]+=x[33];
x[30]++;
}
break;
}
}
}
void func2 (char **f, int *x,int inquery, int *query,int *ch){
switch(funcReturn(f[2])){
case 1: //Подсчитывает, сколько слов начинается с последней буквы первого слова.
{
if(x[32]){
printf("\n\t Количество букв начинающихся с %c - %d",x[32],x[34]);
}
else if(!(x[31])){x[31]=0;x[33]=query[inquery-1];}
else{if (query[0]==x[33]){x[34]++;}}
break;
}
case 2: //Подсчитывает, сколько слов имеют указанную пользователем длину.
{
if(x[32])printf("\n\t Слов имеющих указанную длинну - %d",x[30]);
else{
if(last(inquery,query))inquery--;
if(strquery(f[3],query))x[30]++;
}
break;
}
case 3: //Печатает самое длинное слово в тексте.
{
if(x[32]){printf("\n\t");}
else{
if(x[31]<inquery){
for(int i = 0;i<inquery;i++)
ch[i]=query[i];
x[31]=inquery;
}
}
break;
}
case 4: //Подсчитывает количество знаков препинания (не букв и не цифр).
{
if(x[32]){printf("\n\tЗнаков препинания: %d",x[5]+x[16]+x[18]+x[25]);}
break;
}
/*case 5: //Сортирует текст в порядке возрастания
{
break; Я хз что с этим делать
}*/
case 6: // Находит слова с тире во введенном тексте.
{
if(x[28]);
else{
for(int i = 0;i<inquery;i++){
if(query[i]==L'-'&&inquery>1){
x[30]=x[2];
x[31]=x[3];
x[33]=x[4];
put(x,0,inquery,query);
break;
}
}
}
break;
}
case 7: //Вычисляет количество слов между первой и последней запятой во введенном тексте
{
if(x[32]){printf("\n\tКолличество слов между первой и последней запятой - %d",x[34]);}
else{
if(x[L','-28]>0){
x[31]+=inquery;
if(x[L','-28]>x[33]){
x[34]+=x[31];
x[33]=x[31];
x[31]=0;
}
}
}
break;
}
case 8: //Находит два соседних слова, начинающихся с большой буквы
{
if(x[28]);
else{
if(*query>=L'А'&&*query<=L'Я'){
x[35]++;
if(x[35]==2){
x[30]=x[2];
x[31]=x[3];
x[33]=x[4];
x[35]=0;
printf("\n\t");
put(x,0,x[34],ch);
printf(" - ");
put(x,0,inquery,query);
printf(" | Находятся друг за другом");
}
for(int i = 0;i<inquery;i++)ch[i]=query[i];
x[34]=inquery;
}
else {x[35] = 0;}
}
break;
}
/*case 9: //Сортирует строку в тексте по убыванию
{
Я снова хз
break;
}*/
case 10://Заменяет в каждом слове повторяющиеся буквы на L'–'
{
if(x[32]);
else{
for(int i=0;i<inquery;i++){
for(int j=0;j<inquery;j++)
if(query[j]==query[i])query[j]=query[i]=L'-';
}
put(x,0,inquery,query);
}
break;
}
}
}
void func3 (char **f, int *x,int inquery, int *query){
int alphabet[33*2] = {
L'а',L'б',L'в',L'г',L'д',L'е',L'ё',L'ж',L'з',L'и',L'й',L'к',L'л',L'м',L'н',L'о',
L'п',L'р',L'с',L'т',L'у',L'ф',L'х',L'ц',L'ч',L'ш',L'щ',L'ъ',L'ы',L'ь',L'э',L'ю',L'я',
L'А',L'Б',L'В',L'Г',L'Д',L'Е',L'Ё',L'Ж',L'З',L'И',L'Й',L'К',L'Л',L'М',L'Н',L'О',
L'П',L'Р',L'С',L'Т',L'У',L'Ф',L'Х',L'Ц',L'Ч',L'Ш',L'Щ',L'Ъ',L'Ы',L'Ь',L'Э',L'Ю',L'Я'
};
switch(funcReturn(f[2])){
case 1: //Реверсирует слово. Пример: Привет ->тевирП
{
put(x,inquery-1,0,query);
break;
}
case 2: //Делит слово на два и меняет начало с концом. Пример: жук -> кжу,солнце -> нцесол
{
put(x,0,inquery/2,query);
put(x,inquery/2,inquery,query);
break;
}
case 3: //После каждой гласной буквы вставляется буква L'c' и гласная повторяется. Пример: кот ->косот.
{
int alph[20] = {L'а',L'и',L'е',L'ё',L'о',L'у',L'ы',L'э',L'ю',L'я',
L'А',L'И',L'Е',L'Ё',L'О',L'У',L'Ы',L'Э',L'Ю',L'Я'};
for(int i = 0;i<inquery;i++){
for(int j = 0;j<=20;j++){
if(query[i]==alph[j]){
for(int z = 0;z<inquery-i;z++)
query[inquery+1-z] = query[(inquery-1)-z];
query[i+1]=L'с';
query[i+2]=query[i];
inquery+=2;
i+=2;
}
}
}
put(x,0,inquery,query);
break;
}
case 4: //Каждая буква в слове заменяется на ее позицию в алфавите. Пример: кот ->121620, обработать только буквы.
{
x[25]=-1;
for(int i = 0;i<inquery;i++){
if (query[i] >= L'а' && query[i] <= L'я'){
x[25] = (query[i] - L'а') + 1;
if(query[i]>=alphabet[8])x[25]++;}
else if (query[i] == L'ё')
x[25] = 7;
else if (query[i] >= L'А' && query[i] <= L'Я'){
x[25] = (query[i] - L'А') + 1;
if(query[i]>=alphabet[41])x[25]++;}
else if (query[i] == L'Ё')
x[25] = 7;
if(x[25]!=-1){printf("%d",x[25]);x[25]=-1;}
}
put(x,40,40,query);
break;
}
case 5: //Заменяет буквы верхнего регистра на буквы нижнего и наоборот. Пример: Привет -> пРИВЕТ.
{
for(int i = 0;i<inquery;i++){
for(int j = 0;j<=33*2;j++){
if(query[i]==alphabet[j]&&j<33){
query[i]=alphabet[j+33];
}
else if(query[i]==alphabet[j]&&j>32){
query[i]=alphabet[i-33];
}
}
}
put(x,0,inquery,query);
break;
}
/*case 6: //Заменяет буквы на их двоичное представление из таблицы ASCII.Пример: кот ->101010101010111011100010
{
break;
}*/
case 7: /*Заменяет букву на заданное смещение в пределах алфавита (шифр
Цезаря), смещение задаётся параметром и может быть положительным или
отрицательным. Пример: кот 3 -> нсх, кот -3 -> злп*/
{
while(f[3][x[35]]>=L'0'&&f[3][x[35]]<=L'9'){
x[34] = (x[34]*10)+(f[3][x[35]]-L'0');
x[35]++;
}
for(int i = 0;i<inquery;i++){
for(int j = 0;j<=33;j++){
if(query[i]==alphabet[j]&&j<33){
while(x[34]>33)x[34]-=33;
if(j+x[34]>=33)x[34]-=33;
query[i]=alphabet[j+x[34]];
}
else if(query[i]==alphabet[j]&&j>32){
while(x[34]>33)x[34]-=33;
if(j+x[34]>=66)x[34]-=33;
query[i]=alphabet[j+33+x[34]];
}
}
}
put(x,0,inquery,query);
break;
}
case 8: //Делит слово на два и оставляет большую часть. Пример: жук -> к, солнце -> сол
{
if(inquery%2!=0)x[34]=1;
else x[34]=0;
for (int i = 0; i<(inquery/2)+x[34];i++)
x[35] +=query[i];
for (int i = (inquery/2)+x[34]; i<inquery;i++)
x[36] +=query[i];
if(x[35]>x[36])
put(x,0,(inquery/2)+x[34],query);
else
put(x,(inquery/2)+x[34],inquery,query);
break;
}
case 9: //Делит слово на два и оставляет меньшую часть. Пример: жук -> жу, солнце -> нце
{
if(inquery%2!=0)x[34]=1;
else x[34]=0;
for (int i = 0; i<(inquery/2)+x[34];i++)
x[35] +=query[i];
for (int i = (inquery/2)+x[34]; i<inquery;i++)
x[36] +=query[i];
if(x[35]<x[36])
put(x,0,(inquery/2)+x[34],query);
else
put(x,(inquery/2)+x[34],inquery,query);
break;
}
case 10://Превращает русский текст в транслит русского текста. Пример кот ->kot, жук -> zhuk
{
int translit[43]={
L'a',L'b',L'v',L'g',L'd',L'e' , L'y',/**/L'o' , L'z',/**/L'h' , L'z',L'i',L'y',L'k',L'l',L'm',L'n',L'o',
L'p',L'r',L's',L't',L'u',L'f',L'h',L'c' , L'c',/**/L'h' , L's',/**/L'h' , L's',/**/L'h',/**/L'c',/**/L'h',
L'\'',L'y',L'\'',L'e',L'e' , L'y',/**/L'u' , L'y',/**/L'a'};
for(int i =0;i>inquery;i++){
if(
(query[i] >= alphabet[0] && query[i] <= alphabet[5]) ||
(query[i] >= alphabet[8] && query[i] <= alphabet[23]) ||
(query[i] >= alphabet[27] && query[i] <= alphabet[30]) ||
(query[i] >= alphabet[0+33] && query[i] <= alphabet[5+33]) ||
(query[i] >= alphabet[8+33] && query[i] <= alphabet[23+33]) ||
(query[i] >= alphabet[27+33] && query[i] <= alphabet[30+33]))
{
query[i]=translit[i];
}
else if (query[i] != alphabet[26] || query[i] != alphabet[26+33])
{
for(int z = 0;z<inquery-i;z++)
query[inquery-z] = query[(inquery-1)-z];
query[i]=translit[i];
query[i+1]=translit[i+1];
inquery++;i++;
}
else
{
for(int z = 0;z<inquery-i;z++)
query[inquery-z] = query[(inquery-1)-z];
for(int g =0;g<5;g++)
query[i+g] = translit[i+g];
inquery+=4;i+=4;
}
}
put(x,0,inquery,query);
break;
}
}
}
int last(int inquery,int *query){
if((query[inquery-1]==L'.') ||
(query[inquery-1]==L',') ||
(query[inquery-1]==L'!') ||
(query[inquery-1]==L'?')) {
return 1;
}
return 0;
}
void put(int *x,int i,int inquery,int *query){
if(i<inquery)
for(;i<inquery;i++)
printf("%lc",query[i]);
if(i>inquery)
for(;i>inquery;i--)
printf("%lc",query[i]);
if(x[30]!=x[2]){putwchar(L'\n');}
if(x[31]!=x[3]){putwchar(L'\t');}
if(x[33]!=x[4]){putwchar(L' ');}
x[30]=x[2];
x[31]=x[3];
x[33]=x[4];
}
void printcount(int *x){
int sum = 0;
printf("\nStatistic");
printf("\n\t \"Symb\" - [ammount]\n");
printf("\n\t \"Letters\" - [%d]",x[0]);
printf("\n\t \"Digits\" - [%d]",x[1]);
printf("\n\t \"\\n\" - [%d]",x[2]);
printf("\n\t \"\\t\" - [%d]",x[3]);
printf("\n\t \"space\" - [%d]",x[4]);
for (int i = 33; i <= 47; i++) {
if (x[i-28] > 10)
printf("\n\t \"%c\" - [%d]", i, x[i-28]);
else
sum+=x[i-28];
}
for (int i = 58; i <= 64; i++) {
if(x[i-38]>10)
printf("\n\t \"%c\" = [%d]", i, x[i-32]);
else
sum+=x[i-38];
}
printf("\n\t other - [%d]",sum+x[33]);
}
int str(char *a, char *b) {
int i = 0;
while(a[i] != L'\0' && b[i] != L'\0') {
if(a[i] != b[i]) return 0;
i++;
}
return a[i] == b[i];
}
int strquery(char *a, int *b){
return 0;
}
int funcReturn(char *f){
int swt=0;
if(str(f,"1"))swt=1;
if(str(f,"2"))swt=2;
if(str(f,"3"))swt=3;
if(str(f,"4"))swt=4;
if(str(f,"5"))swt=5;
if(str(f,"6"))swt=6;
if(str(f,"7"))swt=7;
if(str(f,"8"))swt=8;
if(str(f,"9"))swt=9;
if(str(f,"10"))swt=10;
return swt;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef HEAD
#define HEAD
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
// GET
int queryinput(int *x, int *inbuf, int *query);
// FUNC
void func1(char **f, int *x, int inquery, int *query);
void func2(char **f, int *x, int inquery, int *query, int *ch);
void func3(char **f, int *x, int inquery, int *query);
int last(int inquery,int *query);
void put(int *x,int i,int inquery,int *query);
void printcount(int *x);
int str(char *a,char *b);
int strquery(char *a,int *b);
int funcReturn(char *f);
// DEFINE
#define clear printf("\n \033[H\033[J \n")
#define QUERYMAX 40
#define XMAX 40
#endif
+69
View File
@@ -0,0 +1,69 @@
#include "head.h"
int main(int argc, char *argv[]){
setlocale(LC_ALL, "");
if(argc < 2){
printf("Not enough arguments. (-help)\n");
return 1;
}
int query[QUERYMAX];
int assist[QUERYMAX];
int inquery;
int x[XMAX];
for (int i = 0;i<XMAX;i++)x[i]=0;
for (int i = 0;i<QUERYMAX;i++)assist[i]=0;
if(str(argv[1],"-help")||str(argv[1],"-h")){
printf("\nHelpMenu");
printf("\n\tprog [arg1] [arg2] [arg3]");
printf("\n\t[arg1] - Block of func");
printf("\n\t[arg2] - Func num");
printf("\n\t[arg3] - Func input");
return 0;
}
if (argc < 3){
printf("Not enough arguments. (-help)\n");
return 1;
}
int swt=0;
if(((int)*argv[1])>='1' && ((int)*argv[1])<='3'){
swt = ((int)*argv[1]) - '0';
}
else{
printf("Wrong [arg1]\n");
return 1;
}
if(((int)*argv[2])>='0' && ((int)*argv[2])<='9'){
switch(swt){
case 1:
while(queryinput(x,&inquery,query)!=-1)
func1(argv,x,inquery,query);
x[32]=1;
func1(argv,x,inquery,query);
break;
case 2:
while(queryinput(x,&inquery,query)!=-1)
func2(argv,x,inquery,query,assist);
x[32]=1;
func2(argv,x,inquery,query,assist);
break;
case 3:
while(queryinput(x,&inquery,query)!=-1)
func3(argv,x,inquery,query);
break;
}
printcount(x);
}
else{
printf("Wrong [arg2]\n");
return 1;
}
return 0;
}
BIN
View File
Binary file not shown.
@@ -0,0 +1,8 @@
Бог помочь вам, друзья мои,
В заботах жизни, царской службы,
И на пирах разгульной дружбы,
И в сладких таинствах любви!
Бог помочь вам, друзья мои,
И в бурях, и в житейском горе,
В краю чужом, в пустынном море
И в мрачных пропастях земли!
+11
View File
@@ -0,0 +1,11 @@
Средняя длинна слова - 2
Statistic
"Symb" - [ammount]
"Letters" - [33]
"Digits" - [0]
"\n" - [2]
"\t" - [0]
"space" - [12]
other - [0]
+11
View File
@@ -0,0 +1,11 @@
Колл-во букв после 1 и до последнего слова - 181
Statistic
"Symb" - [ammount]
"Letters" - [184]
"Digits" - [0]
"\n" - [8]
"\t" - [0]
"space" - [35]
other - [12]
+10
View File
@@ -0,0 +1,10 @@
Statistic
"Symb" - [ammount]
"Letters" - [184]
"Digits" - [0]
"\n" - [8]
"\t" - [0]
"space" - [35]
other - [12]
+18
View File
@@ -0,0 +1,18 @@
2164 171614162530 3114 5182193033 141610
3 9121620123 71091510 2411819121611 1913217229
10 151 171018123 18194211330151611 518217229
10 3 191315121023 201101519203123 13322310
2164 171614162530 3114 5182193033 141610
10 3 221183323 10 3 7102061119121614 416186
3 1218132 252171614 3 172119202915151614 1416186
10 3 1418125152923 17181617119203323 96141310
Statistic
"Symb" - [ammount]
"Letters" - [184]
"Digits" - [0]
"\n" - [8]
"\t" - [0]
"space" - [35]
other - [46]
+2
View File
@@ -0,0 +1,2 @@
Привет Пока как дела я тебя не знаю
а б в г д
+3
View File
@@ -0,0 +1,3 @@
../prog 1 3 < AP_19_10_1827.txt > output.1_3
../prog 2 8 < AP_19_10_1827.txt > output.2_8
../prog 3 4 < AP_19_10_1827.txt > output.3_4
+1
View File
@@ -0,0 +1 @@
gcc -Wall main.c ./func.c -o prog
+10
View File
@@ -0,0 +1,10 @@
Denton,Strong,0,6
Magee,Avila,2,8
Leilani,Wade,2,1
Oren,Guerra,4,5
Nevada,Clayton,4,8
Halee,Lynn,3,8
Jocelyn,Knight,4,6
Patrick,Sullivan,6,6
Cyrus,Barlow,8,1
Matthew,Vaughn,7,4
1 Denton Strong 0 6
2 Magee Avila 2 8
3 Leilani Wade 2 1
4 Oren Guerra 4 5
5 Nevada Clayton 4 8
6 Halee Lynn 3 8
7 Jocelyn Knight 4 6
8 Patrick Sullivan 6 6
9 Cyrus Barlow 8 1
10 Matthew Vaughn 7 4
+35
View File
@@ -0,0 +1,35 @@
#ifndef HEAD
#define HEAD
// INCLUDE
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
// DEFINE
#define MAXSYMB_IN_NAME 15
#define MAXSYMB_IN_SURNAME 20
#define MAXSYMB_IN_CURROW 20 // SHOOD BE >= THAN MAXSYMB* AND CANNOT BE > 255
#define MAXSTUDENTS 10 // SHOOD BE > 255
#define clear wchar_t clear[] = L"\n \033[H\033[J \n"; for(int i = 0;clear[i]!='\0';i++)putwchar(clear[i])
// FUNC
// === output.c ===
void print_menu_main(void);
void print_wich_student(void);
void print_menu_create(char ws);
void print_menu_edit(char ws);
void print_menu_del(char ws);
void print_no_free_space(void);
// === input.c ===
char get_num(void);
void get_row(wchar_t row[]);
// === logic.c ===
#endif
+18
View File
@@ -0,0 +1,18 @@
#include "head.h"
char get_num(void){
char ws;
do{
wchar_t ch; ws = 0;
while((ch=getwchar())>='0'&&ch<='9')
ws = (ws*10) + (ch-'0');
}while(ws==0);
return ws;
}
void get_row(wchar_t row[]){
}
View File
+92
View File
@@ -0,0 +1,92 @@
#include "head.h"
int main(void){
setlocale(LC_ALL, "");
struct structStudentList{
wchar_t _name[MAXSYMB_IN_NAME+1];
wchar_t _surname[MAXSYMB_IN_SURNAME+1];
char age;
char curse;
};
struct structStudentList students[MAXSTUDENTS+1];
char count_acc[MAXSTUDENTS+1];
{
for (int i = 0; i<MAXSTUDENTS;i++)
count_acc[i] = i;
}
{
wchar_t _currrow[MAXSYMB_IN_CURROW+1];
char flag = 0;
do{ // Main Menu
clear;
print_menu_main();
flag = get_num();
char sw = 0;
char status;
switch(flag){
case 1:
{ // Crete acc
if(count_acc[MAXSTUDENTS]==0){
print_no_free_space();
}
else{
print_menu_create(*count_acc);
}
break;
}
case 2:
{ // Edit acc
print_wich_student();
sw = get_num();
if(sw==-1)return 0;
status = 0;
for(int i = 0;i<MAXSTUDENTS;i++){
status = sw == count_acc[i]?1:0;
if(status) break;
}
if(status){
print_acc_not_exist();
}
else{
}
break;
}
case 3:
{ // Del acc
print_wich_student();
sw = get_num();
if(sw==-1)return 0;
status = 0;
for(int i = 0;i<MAXSTUDENTS;i++){
status = sw == count_acc[i]?1:0;
if(status) break;
}
if(status){
print_acc_not_exist();
}
else{
del_acc(sw);
}
break;
}
case 4:
break;
default:
return 0;
}
}while(flag);
}
return 0;
}
+75
View File
@@ -0,0 +1,75 @@
#include "head.h"
void print_menu_main(void){
wchar_t word[] =
L"\n\tМЕНЮ управления учетными запясями студентов\n 1 - Создать учетку\n2 - Редактировать учетку\n3 - Удалить учетку\n4 - Посмотреть все учетки\n";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
void print_wich_student(void){
wchar_t word[] =
L"\nВведите № учетной записи: ";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
void print_menu_create(char ws){
wchar_t word[] =
L"\n\tМЕНЮ создания учетной записи";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
void print_menu_edit(char ws){
wchar_t word[] =
L"\n\tМЕНЮ редактирования учетной записи\n";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
void print_menu_del(char ws){
{//Print first part of sentense
wchar_t word[] =
L"\nВы уверенны что хотите удалить учетку № ";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
{//Print №
char method = ws>=10?(ws>=100?3:2):1;
char num[3];
for (int i = 0;i<method;i++){
num[i] = ws%10;
ws /= 10;
}
for (int i = method-1;i>=0;i--){
putwchar(num[i]);
}
}
{//Print last part of sentense
wchar_t word2[] =
L" ?\n";
for(int i = 0;word2[i]!='\0';i++){
putwchar(word2[i]);
}
}
}
void print_list(void){
wchar_t word[] =
L"\t";
for(int i = 0;word[i]!='\0';i++){
putwchar(word[i]);
}
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int main() {
char l[26];
for (int i = 0; i < 26; ++i) {
l[i] = 'a' + i;
}
printf("t-t: ");
for (int i = 0; i < 26; ++i) {
printf("%c ", l[i]);
}
printf("\n");
return 0;
}
+17
View File
@@ -0,0 +1,17 @@
#include <stdio.h>
int main(){
long int sum, min, max;
printf("min max: ");
scanf("%ld %ld", &min, &max);
while(min < max){
sum = 0;
for(;min <= max; ++min)
sum += (min*min);
printf("Result: %ld\nmin max: ",sum);
scanf("%ld %ld", &min, &max);
}
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int n[8];
for (int i = 0; i < 8; i++){
printf("num %d: ",i);
scanf("%d", &n[i]);
}
for (int i = 7; i > 0; --i)
printf("%d ", n[i]);
printf("\n");
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
int main() {
int s, n;
double s1, s2;
scanf("%d", &n);
while(n > 0) {
s1 = s2 = 0.0;
s = 1;
for(int i = 1; i <= n; i++) {
s1 += 1.0 / i;
s2 += s * (1.0 / i);
s *= -1;
}
printf("summ1 = %lf\nsumm2 = %lf\nNum: ",s1,s2);
scanf("%d", &n);
}
}
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
int main() {
int x = 2, m[9];
for(int i = 0; i < 8; ++i){
for(int k = 0; k < i; ++k)
x *= 2;
m[i] = x;
x = 2;
}
int i = 0;
do{
printf("%d\n",m[i]);
i++;
}while(i < 8);
return 0;
}
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
int main() {
double a[8], b[8], sum = 0.0;
for (int i = 0; i < 8; ++i){
printf("num %d: ",i);
scanf("%lf", &a[i]);
sum += a[i];
b[i] = sum;
}
for (int i = 0; i < 8; ++i)
printf("%.3lf ", a[i]);
printf("\n");
for (int i = 0; i < 8; ++i)
printf("%.3lf ", b[i]);
printf("\n");
return 0;
}
+24
View File
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main() {
setlocale(LC_ALL, "");
wchar_t s[256];
wchar_t c;
int n = 0, st = 0;
while(st == 0){
wscanf(L"%lc", &c);
st = (c == '\n');
s[n] = c;
n = n + (1 - st);
}
while(n > 0) {
n -= 1;
wprintf(L"%lc", s[n]);
}
printf("\n");
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
int main() {
float a,b,x;
int c = 0;
a = b = x = 100;
do{
a += (x * 0.10);
b += (b * 0.05);
c++;
}while(a >= b);
printf("dafna: %.3f\ndeind: %.3f\nyear: %d",a,b,c);
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int main() {
int sum = 1000000;
int take = 100000;
float proc = 0.08;
int y = 0;
do{
y++;
sum -= take;
sum += (sum * proc);
}while(sum >= 0);
printf("%d",y);
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
int main() {
int d = 5;
int max = 150;
int n = 0;
do{
printf("%d %d\n",d,n);
n++;
d -= n;
d *= 2;
}while(d <= max);
return 0;
}
+12
View File
@@ -0,0 +1,12 @@
#include <stdio.h>
int main(){
int r = 5;
for (int i = 1; i <= r; ++i) {
for (int c = 0; c < i; ++c) {
printf("$");
}
printf("\n");
}
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int main(void) {
int r = 6;
char l;
for (int i = 1; i <= r; ++i) {
l = 'F';
for (int j = 0; j < i; ++j) {
printf("%c", l);
l -= 1;
}
printf("\n");
}
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
int main(void) {
int r = 6;
char l[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int rev = 5;
for (int i = 1; i <= r; ++i) {
for (int j = 0; j < i; ++j) {
printf("%c", l[rev - j]);
}
printf("\n");
}
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
int main(){
int r = 6;
char l = 'A';
for(int i = 1; i <= r; ++i) {
for(int j = 0; j < i; ++j){
printf("%c",l);
l += 1;
}
printf("\n");
}
return 0;
}
+29
View File
@@ -0,0 +1,29 @@
#include <stdio.h>
int main(){
int r = 0;
char l, x;
scanf("%c", &x);
for(char z = 'A'; z <= x; ++z)
r++;
for(int i = 1; i <= r; ++i){
l = 'A';
for(int j = 0; j < r - i; ++j){
printf(" ");
}
for(int j = 0; j < i; ++j){
printf("%c", l);
l++;
}
l -= 2;
for(int j = 0; j < i - 1; ++j){
printf("%c", l);
l--;
}
printf("\n");
}
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
int main(){
int b, t;
printf("bottom: ");
scanf("%d", &b);
printf("top: ");
scanf("%d", &t);
for(;b <= t; ++b){
printf("\n%d\t%d\t%d",b,(b*b),(b*b*b));
}
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(){
setlocale(LC_ALL, "");
wchar_t ch[40];
wscanf(L"%ls", ch);
size_t len = wcslen(ch);
for (int i = len - 1; i >= 0; --i) {
wprintf(L"%lc", ch[i]);
}
printf("\n");
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
int main(){
float a,b;
int s;
printf("a b: ");
s = scanf("%f %f", &a, &b);
while (s == 2){
printf("%.3f / %.3f = %.3f\na b: ",a-b,a+b,((a-b)/(a+b)));
s = scanf("%f %f", &a, &b);
}
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
int x(float a, float b);
int main(){
float a,b;
int s;
printf("a b: ");
s = scanf("%f %f", &a, &b);
while (s == 2){
x(a,b);
printf("a b: ");
s = scanf("%f %f", &a, &b);
}
return 0;
}
int x (float a, float b){
printf("%.3f / %.3f = %.3f\n",a-b,a+b,((a-b)/(a+b)));
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
int main() {
int ch,sp,n,s;
sp = n = s = 0;
while((ch = getchar())!='#'){
switch(ch){
case ' ': n++; break;
case '\n': sp++; break;
default: s++; break;
}}
printf("spaces: %d\tnewln: %d\tsymb: %d\n",sp,n,s);
return 0;
}
+42
View File
@@ -0,0 +1,42 @@
#include <stdio.h>
#define n1 0.15 //tax1
#define n2 0.28
#define m1 17850
#define m2 23900
#define m3 29750
#define m4 14875
int main() {
int m,sw,swt,exit;
float d,tax;
exit = swt = 1;
while(exit){
do{
printf("Choose tarif:\n");
printf("1) odin\t2) main\n");
printf("3) brak sov\t4) Brak razd\n");
printf("5) exit\nInput: ");
sw = getchar();
switch(sw){
case '1': m = m1; swt = 0; break;
case '2': m = m2; swt = 0; break;
case '3': m = m3; swt = 0; break;
case '4': m = m4; swt = 0; break;
case '5': exit = 0; break;
}
}while(swt&&exit);
if(exit){
printf("dohod: ");
scanf("%f",&d);
while(getchar() != '\n');
if (d>m){tax = ((m*n1)+((d-m)*n2));}
else (tax = (d*n1));
printf("Tax: %.2f\n\n\n",tax);
}}
return 0;
}
+60
View File
@@ -0,0 +1,60 @@
#include <stdio.h>
#define arti 2.05
#define svek 1.15
#define carr 1.09
#define skid 0.05
#define zatrporog1 5
#define zatrporog2 20
#define zatrmin 6.50
#define zatrsr 14.00
#define zatrmax 0.5
int main() {
int ch,a,s,c,tmp;
float sk,st,zt;
printf("a - Artishok\nb - Svek\nc -Carrot\nq - quit\nInput: ");
while((ch = getchar())!='q'){
switch(ch){
case 'a':
printf("Arti: ");
scanf("%d",&tmp);
a+=tmp;
break;
case 'b':
printf("svek: ");
scanf("%d",&tmp);
s+=tmp;
break;
case 'c':
printf("Carrot: ");
scanf("%d",&tmp);
c+=tmp;
break;
}
printf("\n\nzakaz:\nArti\tSvek\tCarrot\n%d\t%d\t%d\n",a,s,c);
printf("a - Artishok\nb - Svek\nc - Carrot\nq - deal\nInput: ");
}
if((a>0)||(s>0)||(c>0)){
st = ((a*arti)+(s*svek)+(c*carr));
tmp = (a+s+c);
if(tmp>zatrporog1){
if(tmp>zatrporog2){
zt=(zatrsr+((tmp-zatrporog2)*zatrmax));
}else(zt=zatrsr);
}else(zt=zatrmin);
if(st>100){sk=(st+zt)*skid;}
printf("zakaz: arti-%d Svek-%d Carr-%d\n",a,s,c);
printf("Arti-%d sum-%0.2f stoimost-%0.2f/1\n",a,a*arti,arti);
printf("Svek-%d sum-%0.2f stoimost-%0.2f/1\n",s,s*svek,svek);
printf("Carrot-%d sum-%0.2f stoimost-%0.2f/1\n",c,c*carr,carr);
printf("stoimost-%.2f skidka-%.2f zatrat-%.2f\nitogo: %.2f",st,sk,zt,zt+st-sk);
}
return 0;
}
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
int main(){
int ch,c,m[8];
ch = c = 0;
printf("ascii symb - its num until #\n");
while((ch = getchar()) != '#'){
m[c] = ch;
c++;
if(c == 8){
for(c = 0; c < 8; c++){
switch(m[c]){
case '\n':
printf("\\n - %d ",m[c]);
break;
case ' ':
printf("\"%c\" - %d ",m[c],m[c]);
break;
default:
printf("%c - %d ",m[c],m[c]);
}
}
printf("\n");
c = 0;
}
}
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int main(){
int a,n1,sum1,n2,sum2;
n1 = sum1 = n2 = sum2 = 0;
printf("num: ");
a = 1;
while(scanf("%d", &a) && a != 0){
if (a % 2 == 0){n1++; sum1 += a;}
else ({n2++; sum2 += a;});
printf("num: ");
}
printf("eve nums: %d \t eve summ: %d \t mean: %d\n",n1,sum1,(sum1/n1));
printf("odd nums: %d \t odd summ: %d \t mean: %d",n2,sum2,(sum2/n2));
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
int main() {
int ch,r;
r = 0;
printf("Print something:\n");
while((ch = getchar()) != '#'){
if(ch == '!'){r++;putchar('!');putchar('!');}
else if(ch == '.'){r++;putchar('!');}
else putchar(ch);
}
printf("\nr: %d",r);
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int main() {
int ch,r;
r = 0;
printf("Print something:\n");
while((ch = getchar()) != '#'){
switch(ch){
case '!': r++;putchar('!');putchar('!');break;
case '.': r++;putchar('!');break;
default : putchar(ch);
}
}
printf("\nr: %d",r);
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int a,b,c;
a = b = c = 0;
printf("count ei:\n");
while((a = getchar()) != '#'){
if(a == 'i' && b == 'e'){c++;}
b = a;
}
printf("count: %d",c);
return 0;
}
+29
View File
@@ -0,0 +1,29 @@
#include <stdio.h>
#define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150
int main() {
int h,tax,a;
printf("hours: ");
scanf("%d",&h);
if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
else(tax = a = h*t);
if (tax>m1)
{
if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
else(tax = (m1*n1) + ((tax-m1)*n2));
}
else (tax*=n1);
printf("Acc: %d\nTax: %d\nReceived: %d",a,tax,a-tax);
return 0;
}
+52
View File
@@ -0,0 +1,52 @@
#include <stdio.h>
#define t1 8.75
#define t2 9.33
#define t3 10.00
#define t4 11.20
// #define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150
int main() {
int h,sw,x,swt,exit,scan;
float t,tax,a;
exit = x = swt = scan = 1;
while(exit){
printf("hours: ");
scanf("%d", &h);
while (getchar() != '\n');
do{
printf("Choose tarif:\n");
printf("1) $%.2f/h\t2) $%.2f/h\n",t1,t2);
printf("3) $%.2f/h\t4) $%.2f/h\n",t3,t4);
printf("5) exit\nInput: ");
sw = getchar();
switch(sw){
case '1': t = t1; swt = 0; break;
case '2': t = t2; swt = 0; break;
case '3': t = t3; swt = 0; break;
case '4': t = t4; swt = 0; break;
case '5': exit = 0; break;
}
}while(swt&&exit);
if(!swt && exit){
if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
else(tax = a = h*t);
if (tax>m1)
{
if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
else(tax = (m1*n1) + ((tax-m1)*n2));
}
else (tax*=n1);
printf("Acc: %.3f\nTax: %.3f\nReceived: %.3f\n",a,tax,a-tax);
}}
return 0;
}
+25
View File
@@ -0,0 +1,25 @@
#include <stdio.h>
int pr(long long n);
int main() {
long long int x,i;
printf("Num: ");
if(!(scanf("%lld",&x)))return 1;
for(i = x; i > 1; --i)
if(pr(i))
printf("%lld\t",i);
return 0;
}
int pr(long long n) {
if (n < 2) return 0;
if (n == 2 || n == 3) return 1;
if (n % 2 == 0 || n % 3 == 0) return 0;
for (long long i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return 0;}
return 1;
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
double min(double x, double y);
int main(){
double x,y;
printf("Enter: num1 num2\nEnter: ");
scanf("%lf %lf",&x,&y);
printf("lower: %lf\n",min(x,y));
return 0;
}
double min(double x, double y){
return ((x>y)?x:y);
}
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
void to_base_n(unsigned long *n, int *b);
int main(void){
unsigned long num;
int bin;
printf("Enter: num base(2-10)\t(q to quit):\n");
printf("Enter: ");
while (scanf(" %ld %d", &num, &bin) == 2){
if(bin>1&&bin<11){
to_base_n(&num,&bin);
putchar('\n');
printf("Enter: ");
}else(printf("base is out of range\nEnter: "));
}
return 0;
}
void to_base_n(unsigned long *n, int *b){
int r;
r = *n % *b;
if (*n >= *b){
*n = *n / *b;
to_base_n(n,b);
}
putchar('0' + (r % *b));
return;
}
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
int fibonacci(int n);
int main() {
int n;
printf("Enter: num\nEnter: ");
scanf("%d",&n);
printf("fibonacci(%d) = %d",n,fibonacci(n));
return 0;
}
int fibonacci(int n){
if(n<=0) return 0;
if(n==1) return 1;
int a = 0, b = 1, next;
for(int i = 2;i <= n;i++){
next = a + b;
a = b;
b = next;
}
return b;
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int i = 0;
while(getchar() != EOF)
i++;
printf("%d",i);
return 0;
}
+39
View File
@@ -0,0 +1,39 @@
#include <stdio.h>
int main(){
int ch,c,m[10];
ch = c = 0;
printf("ascii symb - its num\n");
while((ch = getchar()) != EOF){
m[c] = ch;
c++;
if(c == 10){
for(c = 0; c < 10; c++){
switch(m[c]){
case '\n':
printf(" \\n - %3d ",m[c]);
break;
case '\t':
printf(" \\t - %3d ",m[c]);
break;
case ' ':
printf("\"%c\" - %3d ",m[c],m[c]);
break;
default:
if(m[c]<' '){
printf(" ^%c - %3d ", m[c] + 64, m[c]);
}else
if(m[c] == 127){
printf(" ^? %3d ",m[c]);
}else printf("%3c - %3d ",m[c],m[c]);
}
}
printf("\n");
c = 0;
}
}
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int alpha(wchar_t x);
int main() {
setlocale(LC_ALL, "");
int smol = 0,big = 0,symb = 0;
wchar_t x;
while((x = getwchar()) != WEOF){
switch(alpha(x)){
case 1: smol++;break;
case 2: big++;break;
default: symb++;break;
}
}
printf("Пропись: %d\tСтрочных: %d\tОстальное: %d",smol,big,symb);
return 0;
}
int alpha(wchar_t x){
if (x >= L'A' && x <= L'Z')
return 2;
else if (x >= L'a' && x <= L'z')
return 1;
else if (x >= L'А' && x <= L'Я')
return 2;
else if (x >= L'а' && x <= L'я')
return 1;
else if (x == L'Ё')
return 2;
else if (x == L'ё')
return 1;
else
return -1;
}
+22
View File
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main() {
setlocale(LC_ALL, "");
float ch = 0,words = 0,o = 0;
wchar_t x;
while((x = getwchar()) != WEOF){
switch(x){
case ' ':
ch += o;
if(o>0) words++;
o = 0;
break;
default:
o++;
}
}
printf("\nch per word - %.2f\n",ch/words);
return 0;
}
+40
View File
@@ -0,0 +1,40 @@
#include <stdio.h>
int main(void){
int guess = 1,ext = 1;
int x = 50, max = 100, min = 0;
printf("Загадайте число 0 - 100, я буду его отгадывать\n");
printf("Вы должны сказать, это число меньше, больше или это оно\n");
printf("За ответ принимается только l(Меньше) b(Больше) y(Оно)\n");
while(ext != 0){
printf("Это число %d?\n",x);
ext = getchar();
while(getchar()!='\n')
continue;
switch(ext){
case 'l':
max = x - 1;
x = (max+min)/2;
guess++;
break;
case 'b':
min = x + 1;
x = (max+min)/2;
guess++;
break;
case 'y':ext = 0;break;
}
if(x<0||x>100){
printf("Вы загадали число за пределами ожиданий!\n");
ext=0;
break;
}
}
if(x>=0&&x<=100)
printf("Загаданное число - %d\t Число угадываний - %d",x,guess);
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
int main(void){
int ch;
while((ch = getchar()) == ' ')
continue;
while (getchar() != '\n')
continue;
printf("%c",ch);
return 0;
}
+61
View File
@@ -0,0 +1,61 @@
#include <stdio.h>
#define t1 8.75
#define t2 9.33
#define t3 10.00
#define t4 11.20
// #define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150
int main() {
int h,sw,x,swt,exit,scan;
float t,tax,a;
exit = x = swt = scan = 1;
while(exit){
printf("hours: ");
while(scanf("%d", &h)!=1){
printf("input err\n");
if(getchar() == EOF) return 0;
while (getchar() != '\n') continue;
printf("hours: ");
}
while (getchar() != '\n') continue;
do{
while (getchar() != '\n') continue;
printf("Choose tarif:\n");
printf("a) $%.2f/h\tb) $%.2f/h\n",t1,t2);
printf("c) $%.2f/h\td) $%.2f/h\n",t3,t4);
printf("q) exit\nInput: ");
sw = getchar();
if(getchar() == EOF){return 0;}
while (getchar() != '\n') continue;
switch(sw){
case 'a': t = t1; swt = 0; break;
case 'b': t = t2; swt = 0; break;
case 'c': t = t3; swt = 0; break;
case 'd': t = t4; swt = 0; break;
case 'q': exit = 0; break;
default: printf("input err\n");
}
}while(swt&&exit);
if(!swt && exit){
if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
else(tax = a = h*t);
if (tax>m1)
{
if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
else(tax = (m1*n1) + ((tax-m1)*n2));
}
else (tax*=n1);
printf("Acc: %.3f\nTax: %.3f\nReceived: %.3f\n",a,tax,a-tax);
}}
return 0;
}
+63
View File
@@ -0,0 +1,63 @@
#include <stdio.h>
void calc(int func);
int main() {
int exit = 1,sw;
do{
printf("\nВыберите операцию:\n");
printf("a) сложение\tb) вычитание\n");
printf("c) умножение\td) деление\n");
printf("q) exit\nInput: ");
sw = getchar();
switch(sw){
case 'a': calc(1); break;
case 'b': calc(2); break;
case 'c': calc(3); break;
case 'd': calc(4); break;
case 'q': exit = 0; break;
}}while(exit);
return 0;
}
void calc(int func){
float n1,n2;
int x;
printf("Введите первое число: ");
while(scanf(" %f",&n1)!=1){
printf("То что вы ввели не является числом.\n");
printf("Введите первое число: ");
while(getchar()!='\n') continue;
}
printf("Введите второе число: ");
do{
x = (scanf(" %f",&n2) != 1);
if(x){
printf("То что вы ввели не является числом.\n");
printf("Введите второе число: ");
}else
if(n2 == 0&&func==4){
printf("Введите число отличное от 0\n");
printf("Введите второе число: ");
x = 1;
}
while(getchar()!='\n') continue;
}while(x);
switch(func){
case 1:
printf("%f + %f = %f\n",n1,n2,n1+n2);
break;
case 2:
printf("%f - %f = %f\n",n1,n2,n1-n2);
break;
case 3:
printf("%f * %f = %f\n",n1,n2,n1*n2);
break;
case 4:
printf("%f / %f = %f\n",n1,n2,n1/n2);
break;
}
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
void min(char ch, char i, char j);
int main(){
char ch, i, j;
printf("Enter: char i j\nEnter: ");
scanf(" %c %c %c",&ch,&i,&j);
min(ch,i,j);
return 0;
}
void min(char ch, char i, char j){
int c = i;
for(;i<=j;i++){printf("%c\t",i);}
printf("\n");
i = c;
for(;i<=j;i++){printf("%c\t",ch);}
printf("\n");
}
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
void table(char ch, int a, int b);
int main(){
char ch;
int a,b;
printf("Enter: Char num1 num2\nEnter: ");
scanf(" %c %d %d",&ch,&a,&b);
table(ch,a,b);
return 0;
}
void table(char ch, int a, int b){
//for(int i = 0;i<=a;i++){printf("%d",i);}
printf("\n");
for(int i = 1;i<=b;i++){
//printf("%d",i);
for(int x = 1;x<=a;x++){printf("%c",ch);}
printf("\n");
}
}

Some files were not shown because too many files have changed in this diff Show More