程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> Reverse Vowels of a String,reversevowels

Reverse Vowels of a String,reversevowels

編輯:關於C語言

Reverse Vowels of a String,reversevowels


Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:
Given s = "hello", return "holle".

Example 2:
Given s = "leetcode", return "leotcede".

 

 1 char* reverseVowels(char* s) {
 2     int i;
 3     int j;
 4     char temp;
 5     i = 0;
 6     j = strlen(s) - 1;
 7     while(i < j){
 8     
 9         if(s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'A' && s[i] != 'E' && s[i] != 'I' && s[i] != 'O' && s[i] != 'U')
10             i++;
11         if(s[j] != 'a' && s[j] != 'e' && s[j] != 'i' && s[j] != 'o' && s[j] != 'u' && s[j] != 'A' && s[j] != 'E' && s[j] != 'I' && s[j] != 'O' && s[j] != 'U')
12             j--;
13         if((s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o'|| s[i] == 'u' || s[i] == 'A' || s[i] == 'E'|| s[i] == 'I'|| s[i] == 'O'|| s[i] == 'U') && (s[j] == 'a' || s[j] == 'e' || s[j] == 'i' || s[j] == 'o'|| s[j] == 'u' || s[j] == 'A' || s[j] == 'E'|| s[j] == 'I'|| s[j] == 'O'|| s[j] == 'U'))
14         {
15             temp = s[i];
16             s[i] = s[j];
17             s[j] = temp;
18             i++;
19             j--;
20         }
21             
22     }
23     return s;
24 }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved