Count items common to both the lists but with different prices | C ++ implementation to count items common to both the lists but with different prices ; details of an item ; function to count items common to both the lists but with different prices ; for each item of ' list1' check if it is in ' list2' but with a different price ; required count of items ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct item { string name ; int price ; } ; int countItems ( item list1 [ ] , int m , item list2 [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( list1 [ i ] . name . compare ( list2 [ j ] . name ) == 0 ) && ( list1 [ i ] . price != list2 [ j ] . price ) ) count ++ ; return count ; } int main ( ) { item list1 [ ] = { { " apple " , 60 } , { " bread " , 20 } , { " wheat " , 50 } , { " oil " , 30 } } ; item list2 [ ] = { { " milk " , 20 } , { " bread " , 15 } , { " wheat " , 40 } , { " apple " , 60 } } ; int m = sizeof ( list1 ) / sizeof ( list1 [ 0 ] ) ; int n = sizeof ( list2 ) / sizeof ( list2 [ 0 ] ) ; cout << " Count ▁ = ▁ " << countItems ( list1 , m , list2 , n ) ; return 0 ; }