View Code of Problem 101

#include<stdio.h>
#include<string.h>
int main(){
    char str1[100],str2[100];
    while (scanf("%s",&str1)!=EOF) {
        int len = strlen(str1);
        int j = 0;
        int sum=0;
        for (int i = len-1; i >=0; i--) {
            if (str1[i] <= '9' && str1[i] >= '0') {
                sum++;
                str2[j] = str1[i];
                j++;
                if (sum%3==0&&i!=0){
                    str2[j]=',';
                    j++;
                    sum=0;
                }
            }
        }
        for (int k = j-1; k >=0 ; k--) {
            printf("%c",str2[k]);
        }
        printf("\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 101