#include<bits/stdc++.h> using namespace std; // C++ program to check // similarity between two triangles. // Function for SAS congruency int cong_sas(vector<int> s1,vector<int> s2,vector<int> a1,vector<int> a2){ sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); sort(a1.begin(), a1.end()); sort(a2.begin(), a2.end()); // Check for SAS // angle b / w two smallest sides is largest. if (s1[0] == s2[0] && s1[1] == s2[1]){ // # since we take angle b / w the sides. if (a1[2] == a2[2]){ return 1; } } if( s1[1] == s2[1] && s1[2] == s2[2]){ if( a1[0] == a2[0]){ return 1; } } if( s1[2] == s2[2] && s1[0] == s2[0]){ if( a1[1] == a2[1]){ return 1; } } return 0; } // Function for ASA congruency int cong_asa(vector<int> s1,vector<int> s2,vector<int> a1,vector<int> a2){ sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); sort(a1.begin(), a1.end()); sort(a2.begin(), a2.end()); // Check for ASA // side b / w two smallest angle is largest. if (a1[0] == a2[0] && a1[1] == a2[1]){ // since we take side b / w the angle. if (s1[2] == s2[2]){ return 1; } } if( a1[1] == a2[1] && a1[2] == a2[2]){ if (s1[0] == s2[0]){ return 1; } } if( a1[2] == a2[2] && a1[0] == a2[0]){ if (s1[1] == s2[1]){ return 1; } } return 0; } // Function for AAS congruency int cong_aas(vector<int> s1, vector<int> s2, vector<int> a1, vector<int> a2){ sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); sort(a1.begin(), a1.end()); sort(a2.begin(), a2.end()); // Check for AAS // side other two smallest angle is smallest or 2nd smallest. if (a1[0] == a2[0] && a1[1] == a2[1]){ // # since we take side other than angles. if (s1[0] == s2[0] || s1[1] == s2[1]){ return 1; } } if (a1[1] == a2[1] && a1[2] == a2[2]){ if (s1[1] == s2[1] || s1[2] == s2[2]){ return 1; } } if (a1[2] == a2[2] && a1[0] == a2[0]){ if( s1[0] == s2[0] || s1[2] == s2[2]){ return 1; } } return 0; } // Function for HL congruency int cong_hl(vector<int> s1, vector<int> s2){ sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); // Check for HL if (s1[2] == s2[2]){ if( s1[1] == s2[1] || s1[0] == s2[0]){ return 1; } } return 0; } // Function for SSS congruency int cong_sss(vector<int> s1,vector<int> s2){ sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); // # Check for SSS if(s1[0] == s2[0] && s1[1] == s2[1] && s1[2] == s2[2]){ return 1; } return 0; } int main() { // Driver Code vector<int> s1 = {3, 4, 5}; vector<int> s2 = {4, 3, 5}; vector<int> a1 = {90, 60, 30}; vector<int> a2 = {60, 30, 90}; // function call for SSS congruency int sss = cong_sss(s1, s2); // function call for SAS congruency int sas = cong_sas(s1, s2, a1, a2); // function call for ASA congruency int asa = cong_asa(s1, s2, a1, a2); // function call for AAS congruency int aas = cong_aas(s1, s2, a1, a2); // function call for HL congruency int hl = cong_hl(s1, s2); // Check if triangles are congruent or not if (sss || sas || asa || aas || hl){ cout << "Triangles are congruent by " << endl; if(sss) cout << "SSS " << endl; if(sas) cout << "SAS " << endl; if (asa) cout << "ASA " << endl; if (aas) cout << "AAS " << endl; if (hl) cout << "HL " << endl; } else cout << "Triangles are not congruent" << endl; } // The code is contributed by Nidhi goel