“inverser chaque mot de Sring donné” Réponses codées

inverser chaque mot

function reverseWords(str) {
  const allWords = str.split(" ")
  return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
Fylls

inverser chaque mot de Sring donné

// C++ program to reverse individual words in a given
// string using STL list
#include <bits/stdc++.h>
using namespace std;
 
// reverses individual words of a string
void reverseWords(string str)
{
    stack<char> st;
 
    // Traverse given string and push all characters
    // to stack until we see a space.
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] != ' ')
            st.push(str[i]);
 
        // When we see a space, we print contents
        // of stack.
        else {
            while (st.empty() == false) {
                cout << st.top();
                st.pop();
            }
            cout << " ";
        }
    }
 
    // Since there may not be space after
    // last word.
    while (st.empty() == false) {
        cout << st.top();
        st.pop();
    }
}
 
// Driver program to test function
int main()
{
    string str = "Geeks for Geeks";
    reverseWords(str);
    return 0;
}
Funny Flamingo

Inverser chaque mot de chaîne donnée

 
/* 
 *  C Program to Reverse every Word of given String
 */
#include <stdio.h>
#include <string.h>
 
void main()
{
    int i, j = 0, k = 0, x, len;
    char str[100], str1[10][20], temp;
 
    printf("enter the string :");
    scanf("%[^\n]s", str);
 
/* reads into 2d character array */
    for (i = 0;str[i] != '\0'; i++)
    {
        if (str[i] == ' ')
        {
            str1[k][j]='\0';
            k++;
            j=0;
        }
        else
        {
            str1[k][j]=str[i];
            j++;
        }
    }
    str1[k][j] = '\0';
 
/* reverses each word of a given string */
    for (i = 0;i <= k;i++)
    {
        len = strlen(str1[i]);
        for (j = 0, x = len - 1;j < x;j++,x--)
        {
            temp = str1[i][j];
            str1[i][j] = str1[i][x];
            str1[i][x] = temp;
        }
    }
    for (i = 0;i <= k;i++)
    {
        printf("%s ", str1[i]);
    }
}
Funny Flamingo

Réponses similaires à “inverser chaque mot de Sring donné”

Questions similaires à “inverser chaque mot de Sring donné”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code