Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input:
- 42 hfgf=
- output:
- 2829124
- input:
- 1 fgh=
- output:
- 1
- input:
- -1 fgh=
- output:
- 1
- #include <stdio.h>
- long f(size_t x) { return x * x; }
- long g(size_t x) { return x + 1; }
- long h(size_t x) { return x - 1; }
- long doMath(char func, size_t x) {
- long value;
- switch(func) {
- case 'f':
- value = f(x);
- break;
- case 'g':
- value = g(x);
- break;
- case 'h':
- value = h(x);
- break;
- }
- return value;
- }
- int main() {
- char input[50];
- printf("Input: "); fgets(input, 50, stdin);
- int _i = 0, _j = 0;
- int num = 0; char funcs[10];
- long value;
- while (input[_i] != '=') {
- int c = input[_i];
- /* 0-9 */
- if (c >= 48 && c <= 57) {
- num *= 10; num += c - 48;
- }
- /* lowercase a-z */
- if (c >= 97 && c <= 122) {
- funcs[_j++] = (char)c;
- }
- _i++;
- }
- value = num;
- for (_j = 0; funcs[_j] != '