algrorithm super reduced string

Solution for super reduced string algorithm in php

User has n string in english lowercase. In one operation, he can delete any pair of adjacent letters with same value. User wants to reduce string as much as possible. To do this, he will repeat the above operation as many times as it can be performed. Help user to find and print most reducible form of string. If the final string is empty, print Empty String.

e.g. aabccaabcc can be reduced to Empty String. aabcaabcc can be reduced to bcb Input Format And Output Format:

Sample Input 0
aaabccddd

Sample Output 0
abd

Sample Input 1
baab

Sample Output 1
Empty String

Sample Input 2
aa

Sample Output 2
Empty String


Explanation

Sample Case 0:
User can perform the following sequence of operations to get the final string:
aaabccddd->abccddd
abccddd->abddd
abddd->abd
Thus, we print abd.

Sample Case 1:
Shil can perform the following sequence of operations to get the final string:
baab->bb
bb->Empty String



Solution:
<?php
$data="aaabccddd"; //Input string
$str=str_split($data);
$len=count($str);
$initial="";
for($i=0;$i<$len;$i++) {
  if($initial!="" && $str[$i]==$initial) {
  $start=$i-1;
  $end=$i+1;
  $data1=substr($data,0,$start);
  $data2=substr($data,$end);
  $data=$data1.$data2;

  $str=str_split($data);
  $i=0;
  $len=$len-2;
  $initial="";
  }
  $initial=$str[$i];
}
if($data) {
  echo $data;
}
else {
  echo 'Empty String';
}
?>
Sry...can u provide me a solution in c language...plss
By bhakyalashmi at 2017-01-14 10:31:02
Can I give me a solution in c language
By Bhakyalashmi at 2017-01-14 10:29:44
Name
Email
Comments
Back
Funding

We need your support to operate it properly. We have lots of ideas but less fund, so help us with your funding.

Thoughts for the day

If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut.

Albert Einstein
Polls
Which device you use most for facebook application?
Laptop/PC
25%

 


Android
50%

 


IOS
16%

 


Blackberry
9%

 


Tutorial On Request
Q. Ask us for any tutorial or any thing which helps to build your career better.
Email:
Query: