[Hebdo-1] Inversion de Chaine

    Publicités

Users Who Are Viewing This Thread (Total: 0, Members: 0, Guests: 0)

TheHardButcher

Programmeur C/C++
V
Dec 14, 2009
1,461
58
964
France
Titre : Inversion de Chaine


Type : Programmation

Langage Accepté : Tous langages

Difficulté : Très-Facile ( 1/5 )

Description de l'épreuve :

Demande de chaine de caractère puis inversion de celle si.

Exemple :

Entrer
Sortie
Code a compléter ( Si votre langage n'est pas dans ceux proposé, essayer de vous calquez sur les langages présents )

C
Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
// Pas de bibliothèque supplémentaire acceptée

void Inverser(char Texte[]);

int main()
{
    Inverser("Salut !");
}

void Inverser(char Texte[])
{
// VOTRE CODE ICI
}


Gagnant de l'épreuve :
- -I.Paradise-
- ragnarock

Vous avez jusqu'au 31/10/2010 20h00 pour rendre la réponse.
Concours Terminée



Corriger :

- Ma propre version du programme en C :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

void Inverser(char Texte[]);

int main()
{
    Inverser("Salut !");
}

void Inverser(char Texte[])
{

int i = strlen(Texte);
i--;
while ( i > -1)

{
    putchar ( Texte[i--]);
}
}

- La version de Paradise en C#
Code:
public static string Inverser(string texte)
{
	char[] textearraychar = texte.ToCharArray();
	Array.Reverse(textearraychar);
	return new String(textearraychar);
}
- La version de ragnarock

Code:
using System;
using System.Linq;

namespace Tests
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "Salut !";
            Console.WriteLine(str.Reverse());
            Console.ReadLine();
        }
    }

    public static class StringExt
    {
        public static string Reverse(this string str)
        {
            string ret = "";
            char[] tChar = str.ToCharArray().Reverse().ToArray();

            for (int i = 0; i < tChar.Length; i++)
                ret += tChar[i];

            return ret;
        }
    }
}
 
Last edited: