Alphabetical order

As you know problem is Alphabetical sorter but without vowel letter.

What do you suggest me?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include <string>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
void Show(char array[], int size)
{  
    for (int i = 0; i < size; i++)
        std::cout << array[i];
    cout << endl;
}    
  
void BSort(char array[], int size)
{
    for (int i = 0; i < size-1; i++)
    {
        if (array[i] > array[i+1])
        {            
            char temp = array[i+1];
            array[i+1] = array[i];
            array[i] = temp;
             
            i = -1;
        }
    }
}
 
 
int main(int argc, char *argv[])
{    
    string s;
    cin>>s;
    int n  = s.size();
     
    char mychars[n] ;
 for (int i = 0; i < n; i++){
      mychars[i] = s.at(i);
       
      }
   
   int size = sizeof(mychars)/sizeof(char);
    Show(mychars, size);
    BSort(mychars, size);
    Show(mychars, size);
  
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool check (char ch){
	if(ch < 'a' || ch > 'z' || ch =='a' || ch =='e' || ch =='i' || ch =='o' || ch =='u') return 0;
	return 1;
}

int main() {
	
	string s = "ebddfff23E";
	string s2, s3;
	int i=0;
	while(i < s.size()){
		if(check(s[i])) s2 += s[i];		
		else s3 += s[i];		
		i++;
	}
	
	std::sort(s2.begin(), s2.end());
	
	cout << s2 << s3;
	
}
@anup30

thank you :)
another method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <algorithm>

int main() {
	std::string s = "ebddfff23E";
	int i, cur;
	for(i=s.size()-1, cur=i; i>=0; i--){		
		if(s[i]<'a'||s[i]>'z'||s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){
			std::swap(s[i], s[cur--]);				
		}
	}	
	std::sort(s.begin(), s.begin()+cur);	
	
	std::cout << s;	
}
Topic archived. No new replies allowed.