Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Nhập 1 dãy số gồm n số nguyên từ file number.inp
- Yêu cầu:Tính số phần tử khác nhau trong dãy rồi xuất ra file number.out
- VD:2 3 4 4 4 5
- Kết quả là: 4
- */
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <windows.h>
- #include <conio.h>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- int a[100];
- int k;
- // Doc file number.inp
- ifstream Doc ("number.inp");
- if(! Doc.is_open()) {
- cout<<"Khong the mo file.\n";
- return 0;
- }
- else {
- k=0;
- while(Doc.good()) {
- k=k+1;
- Doc>>a[k];
- }
- }
- Doc.close();
- int tg;
- for(int i=1; i < k; i++) {
- for (int j=i+1; j<k; j++){
- if (a[i]>a[j]) {
- tg=a[i];
- a[i]=a[j];
- a[j]=tg;
- }
- }
- }
- int j=1;
- for(int i=1; i < k-1; i++) {
- if (a[i+1]>a[i]) {
- j++;
- }
- }
- // Ghi file number.out
- ofstream Ghi ("number.out");
- Ghi<<j;
- Ghi.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment