diff options
| author | Hyder Hadi <hyder@hyderhadi.xyz> | 2026-03-31 13:37:32 +0300 |
|---|---|---|
| committer | Hyder Hadi <hyder@hyderhadi.xyz> | 2026-03-31 13:37:32 +0300 |
| commit | 6b4e1641366f51e27eae78a2506b4b66d3e9cd4c (patch) | |
| tree | b0030b9b9eb4584f3b81a8344f4faa8a759989cd /simple-C-programs/TouringMachine.c | |
| parent | 30a472f58f204dfbf325b8b389c9f3008aa4c40b (diff) | |
Simple C exercises that i solved :D
Diffstat (limited to 'simple-C-programs/TouringMachine.c')
| -rw-r--r-- | simple-C-programs/TouringMachine.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/simple-C-programs/TouringMachine.c b/simple-C-programs/TouringMachine.c new file mode 100644 index 0000000..e150a42 --- /dev/null +++ b/simple-C-programs/TouringMachine.c @@ -0,0 +1,47 @@ +#include <stdio.h> + +int main() { + char token[256]; + int position = 0, value, length; + char memory[256] = {0}; + + while (scanf("%s", token) == 1) { + + if (token[0] == 'q') { + break; + } + + for (length = 0; token[length] != '\0'; length++) + ; + + if (length > 1) { + value = 0; + for (int i = 0; token[i] != '\0'; i++) { + if (length == 3) { + int tmp = token[i]; + tmp = tmp - '0'; + tmp = tmp * 100; + value += tmp; + length--; + } else if (length == 2) { + int tmp = token[i]; + tmp = tmp - '0'; + tmp = tmp * 10; + value += tmp; + length--; + } else if (length == 1) { + int tmp = token[i]; + tmp = tmp - '0'; + value += tmp; + length--; + memory[position] = value; + } + } + } else if (token[0] == '>') { + position++; + } else if (token[0] == '<') { + position--; + } + } + printf("Memory:\n%s\n", memory); +}
\ No newline at end of file |
