#include #include #include #include #include int readline(char *buff) { if(!gets(buff)) return EOF; int last = strlen(buff) - 1; while(last >= 0 && (buff[last] == '\r' || buff[last] == '\n')) buff[last--] = 0; return 1; } int isintstring (char *s) { if(*s == 0) return false; while (*s != '\0') if (!isdigit(*s++)) return false; return true; } int isdoublestring (char *s) { if (!isdigit(*s++)) return false; while (isdigit(*s)) s++; if (*s++ != '.') return false; if (!isdigit(*s++)) return false; while (isdigit(*s)) s++; if (*s++ != '\0') return false; return true; } struct inputval { enum { Int, Double, String } tag; union { int theint; double thedouble; char* thestring; } value; }; int main (void) { struct inputval input[1000]; char buff[100]; int n = 0; while(readline(buff) != EOF) { if (isintstring(buff)) { input[n].tag = Int; input[n].value.theint = atoi(buff); } else if (isdoublestring(buff)) { input[n].tag = Double; input[n].value.thedouble = atof(buff); } else { input[n].tag = String; input[n].value.thestring = malloc(strlen(buff) + 1); strcpy(input[n].value.thestring, buff); } n++; } for (int i = 0; i < n; i++) if (input[i].tag == Int) { int j = input[i].value.theint; if (0 <= j && j < n) { struct inputval *v = &input[j]; switch (v->tag) { case String: { int l = strlen(v->value.thestring); char *newstr = malloc(2 * l + 1); strcpy(newstr, v->value.thestring); strcat(newstr, v->value.thestring); free(v->value.thestring); v->value.thestring = newstr; break; } case Int: v->value.theint++; break; case Double: v->value.thedouble *= 2.0; break; } } } // print result and free memory for (int i = 0; i < n; i++) { switch (input[i].tag) { case Int: printf("%d\n", input[i].value.theint); break; case Double: printf("%f\n", input[i].value.thedouble); break; case String: printf("%s\n", input[i].value.thestring); free(input[i].value.thestring); break; } } return 0; }