Tranvick

1

Jun 29th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct item {
  7.     char s[100];
  8.     item * next;
  9. } * first, * last;
  10.  
  11. char s[100];
  12. int n;
  13.  
  14. int main() {
  15.     ifstream fin("input.txt");
  16.     ofstream fout("output.txt");
  17.     fin >> n;
  18.     fin.getline(s, 100);
  19.     first = last = NULL;
  20.     while (n--) {
  21.         fin.getline(s, 100);
  22.         item * cur = new item;
  23.         cur -> next = NULL;
  24.         strcpy(cur -> s, s);
  25.         fout << s << endl;
  26.         if (first == NULL)
  27.             first = last = cur;
  28.         else {
  29.             cur -> next = first;
  30.             first = cur;
  31.         }
  32.     }
  33.     fout << endl;
  34.     for (item * cur = first; cur; cur = cur -> next)
  35.         fout << cur -> s << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment