Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to sort a string in c++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	srting str; // First, declare a string.
  	sort(str.begin() , str.end()); // Then sort it by using this method. It is much more convenient.
  	cout << str << endl; // Last of all, print out the string.
}
Comment

how to sort a string in c++

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i-1;j++){
      if(s[j]>s[j+1]) swap(s[j],s[j+1]);
    }
  }
    cout<<s<<endl;
  return 0;
}
Comment

how to sort string array in c++

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n - 1; j++)
            if (s[j] > s[j + 1])
                swap(s[j], s[j + 1]);
    for (int i = 0; i < n; i++)
        cout << s[i] << endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: rotate in cpp 
Cpp :: getline cin is being skipped 
Cpp :: c++ run loop for 5 seconds 
Cpp :: border radius layout android xml 
Cpp :: c++ randomization 
Cpp :: scale window sdl2 
Cpp :: ifstream relative file path 
Cpp :: fast io c++ 
Cpp :: cpp infinity 
Cpp :: finding no of unique characters in a string c++ 
Cpp :: how to access struct variables in c++ 
Cpp :: c++ print byte as bit 
Cpp :: how to free the vector c++ 
Cpp :: locate specific string letters c++ 
Cpp :: float max value c++ 
Cpp :: c++ program to calculate discount 
Cpp :: structure and function c++ 
Cpp :: getch c++ library 
Cpp :: how to check is some number is divisible by 3 in c++ 
Cpp :: c++ switch string 
Cpp :: c++ program to take input from user 
Cpp :: strip space from string cpp 
Cpp :: in c++ the default value of uninitialized array elements is 
Cpp :: split string on character vector C++ 
Cpp :: c++ nagetive to positive numbers 
Cpp :: how to create array with not constant size in cpp 
Cpp :: cpp Sieve algorithm 
Cpp :: c++ foreach 
Cpp :: count bits c++ 
Cpp :: how to get the size of a vector in c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =