|
|
вернуться в форумWrong Answer (Test 3) I don't know why Please help if you can #include <stdio.h> #include <stdlib.h> #include <math.h> #include <malloc.h> int main() { char* Buffer =(char*) calloc(1, sizeof(*Buffer)); int i=0,j, ch,k; double value =0.0f; int wasValueReadingStarted=0, NeedToBePrinted=1; ch = getchar(); while (ch != EOF) { if(i) { Buffer = (char*)realloc(Buffer, (i+1)*sizeof(*Buffer)); } Buffer[i]=ch; ch = getchar(); i++; }
j = i-1;
while (j>=0) { ch = Buffer[j]; if (ch ==' ' || ch == '\t' || ch == '\n') { k=0; if (wasValueReadingStarted && NeedToBePrinted) { printf("%.4f\n", sqrt(value)); NeedToBePrinted=0; value = 0.0f; } } else { value += (ch-'0')*pow(10,k); wasValueReadingStarted = 1; NeedToBePrinted=1; k++; } j--; } if (wasValueReadingStarted && NeedToBePrinted) printf("%.4f\n", sqrt(value)); return 0; } Edited by author 03.05.2013 17:36 |
|
|