Here is my solution which is "accepted", 0.00 time and 2.00M used, in C language.
#include<stdio.h>
int main(void) {
int x;
x=0;
while(x!=42) {
scanf("%d",&x);
if(x!=42)
printf("%d\n",x);
}
return 0;
}
And here is a for-fun-code which solve the same problem, but closer to the example was given in the problem page. In C language too. Use in/output file.
#include<stdio.h>
#include<stdlib.h>
#define fi "d:\\program\\text\\ipTEST.txt"
#define fo "d:\\program\\text\\opTEST.txt"
struct Node {
int data;
struct Node *next;
};
struct Node *head;
void Inl(int); //insert last
void Clr(void); //clear
void Input(void);
void Output(void);
int main(void) {
head=NULL;
Input();
Output();
return 0;
}
void Inl(int x) {
struct Node *t;
t=(struct Node *)malloc(sizeof(*t));
t->data=x;
t->next=NULL;
if(head==NULL)
head=t;
else {
struct Node *u;
u=head;
while(u->next!=NULL)
u=u->next;
u->next=t;
}
}
void Clr(void) {
struct Node *prev,*curr;
prev=head;
head=NULL;
curr=prev->next;
free(prev);
while(curr!=NULL) {
prev=curr;
curr=curr->next;
free(prev);
}
}
void Input(void) {
FILE *f=fopen(fi,"r");
if(!f)
return;
else {
int x;
while(!feof(f)) {
fscanf(f,"%d",&x);
Inl(x);
}
fclose(f);
}
}
void Output(void) {
FILE *f=fopen(fo,"w");
if(!f)
return;
else {
struct Node *t;
t=head;
while(t->data!=42) {
fprintf(f,"%d\n",t->data);
t=t->next;
}
Clr();
fclose(f);
}
}