Advertisement
thienlang

FILE

Oct 11th, 2015
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. #define MAX 100
  10. #define MAXLENGTH 10
  11.  
  12. struct TU
  13. {
  14.     char noidung[MAXLENGTH];
  15.     int dem;
  16. };
  17.  
  18. TU danhsach[MAX];
  19. int spt = 0;
  20.  
  21. int main()
  22. {
  23.     char temp[MAXLENGTH];
  24.     int timthay;
  25.     ifstream f("DATA.IN"); //ifstream : Ho Tro doc tu file
  26.     while (!f.eof())
  27.     {
  28.         f >> temp;
  29.         timthay = 0;
  30.         strcpy_s(temp, _strlwr(temp));
  31.         for (int i = 0; i < spt; i++)
  32.         {
  33.             if (strcmp(danhsach[i].noidung, temp) == 0)
  34.             {
  35.                 timthay = 1;
  36.                 danhsach[i].dem++;
  37.                 break;
  38.             }
  39.         }
  40.         if (!timthay)
  41.         {
  42.             strcpy(danhsach[spt].noidung, temp);
  43.             danhsach[spt].dem = 1;
  44.             spt++;
  45.         }
  46.     }
  47.     ofstream f_out("KETQUA.OUT"); //OFSTREAM : Ho tru xuat file
  48.     for (int i = 0; i < spt; i++)
  49.     {
  50.         f_out << danhsach[i].noidung << " " << danhsach[i].dem << endl;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement