Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
922 B
4
Indexable
Never
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include "function.h"

int solver(int **ptr, int *sum, char *s){
    
    int len = strlen(s);
    int j = 0, tmp = 0, pos = 1;
    for(int i = 0; i <= len; i++){
        if(tmp == 1 && (isdigit(s[i]) == 0 || i == len)){
            *sum += *ptr[j];
            tmp = 0, pos = 1;
            j++;
        }
        if(isdigit(s[i]) == 0 && s[i] != '-') pos = 1;
        if(s[i] == '-')  pos = 0;
        if(isdigit(s[i]) == 1){
            tmp = 1;
            if(pos == 1){
                *ptr[j] = (*ptr[j])*10 + s[i] - '0';
            }
            else{
                if(*ptr[j] == 0){
                    *ptr[j] = -(s[i]-'0');
                }
                else *ptr[j] = (*ptr[j])*10 - (s[i]-'0');//如果是負數,後面的數字用-的來加上去
            }
        }
    }
    return j;
}