Advertisement
Guest User

Untitled

a guest
May 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. //int arr[100];
  5. void doctep(float a[], int &n){
  6.     fstream fdoc("input.txt",ios::in);
  7.     fflush(stdin);
  8.     fdoc>>n;
  9.     fflush(stdin);
  10.     for(int i=0;i<n;i++) fdoc>>a[i];
  11.     fflush(stdin);
  12.     fdoc.close();
  13. }
  14. void demso(float a[], int n, float so[], int solan[], int &tongso){
  15.     int danhdau[101],k=0;
  16.     for(int i=0;i<n;i++) danhdau[i] = 0;
  17.     for(int i=0;i<n-1;i++){
  18.         if(danhdau[i] == 0){
  19.             danhdau[i] = 1;
  20.             so[k] = a[i];
  21.             solan[k] = 1;
  22.             for(int j=i+1;j<n;j++){
  23.                 if(a[i] == a[j]){
  24.                     solan[k]++;
  25.                     danhdau[j] = 1;
  26.                 }
  27.             }
  28.             k++;
  29.         }
  30.     }
  31.     tongso = k;
  32. }
  33. void ghitep(float so[], int solan[], int &tongso){
  34.     fstream fghi("input26.txt",ios::out);
  35.     for(int i=0;i<tongso;i++){
  36.         fghi<< so[i]<<" xuat hien: "<<solan[i]<<" lan"<<endl;
  37.     }
  38.     printf("Ghi Thanh Cong");
  39.     fghi.close();
  40. }
  41. main(){
  42.     float a[100],so[100];
  43.     int n,solan[100] ,tongso;
  44.     doctep(a,n);
  45.     //cout<<n;
  46. //  printf("%d\n",n);
  47. //  for(int i=0;i<n;i++) printf("%f ",a[i]);
  48.     demso(a,n,so,solan,tongso);
  49. //  for(int i=0;i<tongso;i++) printf("%f : %d\n",so[i],solan[i]);
  50.     ghitep(so,solan,tongso);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement