Hi

Isnt this the Kadane's (largest subarray) problem ?

Rgds
Supraja J

On Fri, May 27, 2011 at 9:41 AM, anshu mishra <anshumishra6...@gmail.com>wrote:

> @all go through this code
>
> #include<iostream>
> #include<algorithm>
>
> using namespace std;
> bool compare(int a, int b)
> {
>         string u, v;
>         u = v = "";
>         while (a)
>         {
>                 u += (a % 10 + '0');
>                 a/=10;
>         }
>         while (b)
>         {
>                 v += (b % 10 + '0');
>                 b/=10;
>         }
>         int i = 0, j = 0;
>         reverse(u.begin(), u.end());
>         reverse(v.begin(), v.end());
>         while (i < u.size() || j < v.size())
>         {
>                 if (i == u.size()) i = 0;
>                 if (j == v.size()) j = 0;
>                 for (; i < u.size() && j < v.size(); i++, j++)
>                 {
>                         if (u[i] == v[j]) continue;
>                         return (u[i] > v[j]);
>                 }
>         }
>         if (u.size() == v.size()) return true;
> }
> int main()
> {
>         int n;
>         cin >> n;
>         int ar[n];
>         int i;
>         for (i = 0; i < n; i++)
>         {
>                 cin >> ar[i];
>         }
>         sort (ar, ar +n, compare);
>         for (i = 0; i < n; i++) cout << ar[i];
>         cout << endl;
>         return 0;
> }
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to