Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string.h>
- #include <ctype.h>
- using namespace std;
- int isVowel(char ch);
- int isConsonant(char ch);
- int main()
- {
- //0 1 2 3 4 5 6
- //p r o g r a m
- char s[11];
- cin >> s;
- int pozitiePrimaVocala = -1;
- int pozitieUltimaConsoana = -1;
- for (int i = 0; i < strlen(s); i++) {
- if (pozitiePrimaVocala == -1 && isVowel(s[i])) {
- pozitiePrimaVocala = i;
- }
- else if (isConsonant(s[i])) {
- pozitieUltimaConsoana = i;
- }
- }
- if (pozitiePrimaVocala != -1 && pozitieUltimaConsoana != -1) {
- swap(s[pozitiePrimaVocala], s[pozitieUltimaConsoana]);
- cout << s;
- }
- else {
- cout << "IMPOSIBIL";
- }
- return 0;
- }
- int isVowel(char ch) {
- return strchr("aeiouAEIOU", ch) != NULL;
- }
- int isConsonant(char ch) {
- if (((ch > 'a' && ch <= 'z') || (ch > 'A' && ch <= 'Z')) &&
- !isVowel(ch)
- ) {
- return 1;
- }
- else {
- return 0;
- }
- }
- // isalpha => verifica daca un caracter este alfabetic sau nu(adica daca este o litera sau nu)
- //int isConsonant(char ch) {
- // if ( isalpha(ch) && !isVowel(ch)) {
- // return 1;
- // }
- // else {
- // return 0;
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment