-
Description This is a simple solution in C++ as I noticed there were no C++ solutions. I do not know unit testing in C++ so, I manullay call these functions from main function.
Code bool verify_sum(std::string name1,std::string name2) { int i,sum1=0,sum2=0; if(name1.size() == 0 || name2.size() == 0) return true; for(i=0;i<name1.size();i++) { sum1 += name1[i] ; } for(i=0;i<name2.size();i++) { sum2 += name2[i] ; } return ((sum1-sum2) == 0); } int main() { int i; std::string store[10] = {"Sebastian","Patricia","Anna","Nana","John"}; // I don't really know how to do unit testing on C++ :( for(i=0;i<4;i++) { if(verify_sum(store[i],store[i+1]) == true) printf("True\n"); else printf("False\n"); } return 0; }
Output:
-
Code verify_sum = lambda a, b: sum(map(ord, a)) == sum(map(ord, b)) if a and b else None- #include <string>
- bool verify_sum(std::string name1,std::string name2)
- {
- int i,sum1=0,sum2=0;
- if(name1.size() == 0 || name2.size() == 0)
- return true;
- for(i=0;i<name1.size();i++)
- {
- sum1 += name1[i] ;
- }
- for(i=0;i<name2.size();i++)
- {
- sum2 += name2[i] ;
- }
- return ((sum1-sum2) == 0);
- }
- int main()
- {
- int i;
- std::string store[10] = {"Sebastian","Patricia","Anna","Nana","John"};
- // I don't really know how to do unit testing on C++ :(
- for(i=0;i<4;i++)
- {
- if(verify_sum(store[i],store[i+1]) == true)
- printf("True\n");
- else
- printf("False\n");
- }
- return 0;
- }
Test Cases test.assert_equals(verify_sum("Sebastian", "Patricia"), False)test.assert_equals(verify_sum("Anna", "Nana"), True)test.assert_equals(verify_sum("John", None), None)
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}