Wednesday, May 10, 2017

URI Solution 1244 Sort by Length | Data Structures

URI Solution 1244 Sort by Length | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1244

Problem Name: URI Problem  1244 Sort by Length
Problem Number : URI Problem  1244 Sort by Length  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus


URI Solution  1244 Sort by Length  Code in CPP:


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

string arr[51];
int x;

bool compare(string a, string b) { return (a.length() <= b.length()); }

void split(string word)
{
 int size = word.length();
 int i = 0, x = 0, j = 0;
 string s;

 while(i <= size)
 {
  if(word[i] == ' ' || word[i] == '\0'){
   s = word.substr(j, i - j);
   arr[x] = s;
   j = i + 1;
   x++;
  }
  i++;
 }

 stable_sort(arr, arr + x, compare);
 reverse(arr, arr + x);

 for (i = 0; i < x; ++i)
 {
  cout << arr[i];
  if(i != (x - 1))
   cout << " ";
 }

 cout << endl;
}

int main(int argc, char const *argv[])
{
 int n, i;
 string word;

 cin >> n; cin.ignore();

 while(n--)
 {
  getline(cin, word);
  split(word);
 }

 return 0;
}

Tag: Uri solve 1244 Sort by Length  1244 Sort by Length  , Uri solution 1244 Sort by Length , URI 1244 Sort by Length  oj Solve

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.