Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <string.h>
- using namespace std;
- #define MAX 100
- #define MAXLENGTH 10
- struct TU
- {
- char noidung[MAXLENGTH];
- int dem;
- };
- TU danhsach[MAX];
- int spt = 0;
- int main()
- {
- char temp[MAXLENGTH];
- int timthay;
- ifstream f("DATA.IN"); //ifstream : Ho Tro doc tu file
- while (!f.eof())
- {
- f >> temp;
- timthay = 0;
- strcpy_s(temp, _strlwr(temp));
- for (int i = 0; i < spt; i++)
- {
- if (strcmp(danhsach[i].noidung, temp) == 0)
- {
- timthay = 1;
- danhsach[i].dem++;
- break;
- }
- }
- if (!timthay)
- {
- strcpy(danhsach[spt].noidung, temp);
- danhsach[spt].dem = 1;
- spt++;
- }
- }
- ofstream f_out("KETQUA.OUT"); //OFSTREAM : Ho tru xuat file
- for (int i = 0; i < spt; i++)
- {
- f_out << danhsach[i].noidung << " " << danhsach[i].dem << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement