#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; float litr=0, temp=0, sumtemp=0, sumocz=0; cin >> k; for(int kk =0; kk<k; kk++) { cin >> n; int **tablica = new int *[n]; litr = temp = sumocz = sumtemp = 0; for(int i=0; i<n; i++) { tablica[i]=new int [3]; for(int j=0; j<3; j++) cin >> tablica[i][j]; sumtemp += tablica[i][1]; sumocz += tablica[i][2]; temp = (litr*temp + tablica[i][0]*tablica[i][1])/(litr + tablica[i][0]); litr += tablica[i][0]; } if(sumocz != sumtemp) cout << "NIE" << endl; else { for(int i=0; i<n-1; i++) { temp -= (litr * temp - tablica[i][0] * tablica[i][2])/(litr - tablica[i][0]); litr -= tablica[i][0]; } if(temp == tablica[n-1][3]) cout << "TAK" << endl; else cout << "NIE" << endl; } for(int i=0; i<n; i++) delete[] tablica[i]; delete[] tablica; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; float litr=0, temp=0, sumtemp=0, sumocz=0; cin >> k; for(int kk =0; kk<k; kk++) { cin >> n; int **tablica = new int *[n]; litr = temp = sumocz = sumtemp = 0; for(int i=0; i<n; i++) { tablica[i]=new int [3]; for(int j=0; j<3; j++) cin >> tablica[i][j]; sumtemp += tablica[i][1]; sumocz += tablica[i][2]; temp = (litr*temp + tablica[i][0]*tablica[i][1])/(litr + tablica[i][0]); litr += tablica[i][0]; } if(sumocz != sumtemp) cout << "NIE" << endl; else { for(int i=0; i<n-1; i++) { temp -= (litr * temp - tablica[i][0] * tablica[i][2])/(litr - tablica[i][0]); litr -= tablica[i][0]; } if(temp == tablica[n-1][3]) cout << "TAK" << endl; else cout << "NIE" << endl; } for(int i=0; i<n; i++) delete[] tablica[i]; delete[] tablica; } return 0; } |