TEXT   43
Untitled
Guest on 11th March 2023 03:53:19 AM


  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. const int MAX =1010;
  5. int n; // so luong cv
  6. int a[MAX]; // ma trận cv
  7. int P1=0;
  8. int P2=0;
  9. int P3=0;
  10.  
  11. int CH2_VD3b(){
  12.    
  13.     for (int i=0;i<n;i++){
  14.         if(P1<=P2 && P1<=P3){
  15.             P1+=a[i];
  16.         }
  17.         else if (P2<=P1 && P2<=P3){
  18.             P2+=a[i];
  19.         }
  20.         else if (P3<=P1 && P3<=P2) {
  21.             P3+=a[i];
  22.         }
  23.        
  24.      
  25.     }
  26.     int result;
  27.     if (P1>P2) result = P1;
  28.     else result = P2;
  29.     if (result<P3) result=P3;
  30.     return result;
  31.  
  32. }
  33.        
  34.  
  35.  
  36. int main() {
  37.     char *s = (char*)"D:\\C-C++\\csttnt\\schedulea.txt";
  38.      
  39.     FILE *f=fopen(s,"r+");
  40.     if(f == NULL)
  41.     {
  42.       printf("Error!");  
  43.       exit(1);            
  44.     }
  45.     fscanf(f,"%d",&n);
  46.     for (int i = 0; i < n; i++) {      
  47.             fscanf(f,"%d",&a[i]);
  48.          // nhập ma trận kế cận
  49.        
  50.     }
  51.     fclose(f);
  52.  
  53.     cout<< CH2_VD3b(

Raw Paste

Login or Register to edit or fork this paste. It's free.