C
- voluntas
- @ignis_fatuus
- 沖 観行
- 清楚なC++メイドBOT
- @tzik_tack
- wraith13
- @hotwatermorning
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- @nobu_k
- mtera (@tonakou)
- redboltz (ステーキ)
- Usagi Ito
- @rydotyosh
- まろ(@_marony)
- @EzoeRyou
- うさみけんた(@tadsan)
- @zakkas783(フォアグラ)
- @take_cheeze
- TAKEI Yuya
- daisy1754
- @mumumu
- 堀尾典孝
- @inazawa32
- 鈴木勝博(@ksattkb)
- 黒澤 亮二
- k-ballo
- taichi
- @ueokande
- 100% Pure NEET
- djeeno
- @two_ack
- @char8_t
- sublimer
- tai2
- Freezer
- @m_akihiro
- 松崎啓治
- I (@wx257osn2)
- @yuushimizup
- @fukasawah
- 暢気
x
56
push(stack, cexp(pop(stack) * clog(pop(stack))));1
2
3
4
5
6
7
typedef struct node {8
double data;9
SLIST_ENTRY(node) link;10
} NODE;11
12
typedef SLIST_HEAD(, node) STACK;13
14
void push(STACK *stack, double data) {15
NODE *node = malloc(sizeof(NODE));16
node->data = data;17
SLIST_INSERT_HEAD(stack, node, link);18
}19
20
double pop(STACK *stack) {21
double data = SLIST_FIRST(stack)->data;22
SLIST_REMOVE_HEAD(stack, link);23
return data;24
}25
26
int main(void) {27
char *line = NULL;28
size_t len = 0;$ gcc prog.c -Wall -Wextra -std=gnu11 "-lm"
Stdin
3 4 2 * 1 5 - 2 3 ^ ^ / + Code
[C] gcc HEAD 10.0.0 20190605 (experimental)
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
typedef struct node {
double data;
SLIST_ENTRY(node) link;
} NODE;
typedef SLIST_HEAD(, node) STACK;
void push(STACK *stack, double data) {
NODE *node = malloc(sizeof(NODE));
node->data = data;
SLIST_INSERT_HEAD(stack, node, link);
}
double pop(STACK *stack) {
double data = SLIST_FIRST(stack)->data;
SLIST_REMOVE_HEAD(stack, link);
return data;
}
int main(void) {
char *line = NULL;
size_t len = 0;
while (getline(&line, &len, stdin) != -1) {
line[strcspn(line, "\r\n")] = '\0';
char *op;
STACK *stack = malloc(sizeof(STACK));
while ((op = strsep(&line, " ")) != NULL) {
if (!strcmp(op, "+")) {
push(stack, pop(stack) + pop(stack));
} else if (!strcmp(op, "-")) {
push(stack, -(pop(stack) - pop(stack)));
} else if (!strcmp(op, "*")) {
push(stack, pop(stack) * pop(stack));
} else if (!strcmp(op, "/")) {
push(stack, 1 / (pop(stack) / pop(stack)));
} else if (!strcmp(op, "^")) {
push(stack, cexp(pop(stack) * clog(pop(stack))));
} else {
push(stack, strtod(op, NULL));
}
}
printf("%g\n", pop(stack));
}
return 0;
}
3 4 2 * 1 5 - 2 3 ^ ^ / +
Start
3.00012
0
Finish
- voluntas
- @ignis_fatuus
- 沖 観行
- 清楚なC++メイドBOT
- @tzik_tack
- wraith13
- @hotwatermorning
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- @nobu_k
- mtera (@tonakou)
- redboltz (ステーキ)
- Usagi Ito
- @rydotyosh
- まろ(@_marony)
- @EzoeRyou
- うさみけんた(@tadsan)
- @zakkas783(フォアグラ)
- @take_cheeze
- TAKEI Yuya
- daisy1754
- @mumumu
- 堀尾典孝
- @inazawa32
- 鈴木勝博(@ksattkb)
- 黒澤 亮二
- k-ballo
- taichi
- @ueokande
- 100% Pure NEET
- djeeno
- @two_ack
- @char8_t
- sublimer
- tai2
- Freezer
- @m_akihiro
- 松崎啓治
- I (@wx257osn2)
- @yuushimizup
- @fukasawah
- 暢気