Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 6. Combine List of Letters
- //Write a script that reads two array of letters l1 and l2 and combines them: appends all letters c from l2 to the end of l1, but only //when c does not appear in l1. Print the obtained combined list. All lists are given as sequence of letters separated by a single space, //each at a separate line. Use ArrayList<Character> of chars to keep the input and output lists
- <?php
- //$str1=array('h', 'e', 'l', 'l', 'o');
- //$str2=array('l','o','w');
- $str1=array('a', 'b', 'c', 'd');
- $str2=array('x','y','z');
- for($i=0;$i<=count($str2)+1;$i++){
- for($j=0;$j<=count($str1)+1;$j++){
- if ($str1[$j]==$str2[$i]) {
- $flag=0;
- break;
- }
- elseif($str1[$j]!=$str2[$i]){
- $flag++;
- }
- }
- if($flag!=0){
- $str1[]=$str2[$i];
- }
- $flag=0;
- }
- echo '<pre>' . print_r($str1, true) . '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment