“Palíndromo” Respostas de código

Palíndromo

// can we generate palindrome string by suffling 
// the character of the string s 
public bool CanBePalindrome(string s)
{
    var dict = new Dictionary<char, int>();
    for (int j =0; j < s.Length; j++)
    {
        var item = s[j];
        if (dict.ContainsKey(item))
        {
            dict[item]++;
            if (dict[item] == 2)
            {
                dict.Remove(item);
            }
        }
        else
        {
            dict.Add(item, 1);
        }
    }
    return dict.Count <= 1;
}
PrashantUnity

Palíndromo

var letters = [];
var word = "racecar"  //bob

var rword = "";

//put letters of word into stack
for (var i = 0; i < word.length; i++) {
    letters.push(word[i]);
}

//pop off the stack in reverse order
for (var i = 0; i < word.length; i++) {
    rword += letters.pop();
}

if (rword === word) {
    console.log("The word is a palindrome");
}
else {
    console.log("The word is not a palindrome");
}   
Edicemi

Palíndromo

// Should Check if the argument passed is a string
function isPalindrome(str){
	return typeof str === "string"
		? str.split("").reverse().join("") === str
		: "Value is not a type string";
}
hacksaw

Palíndromo

//Reverses every character in the string
func Reverse(s string) (result string){
	for _,v := range s {
	  result = string(v) + result
	}
	return 
    }

//Check if the string is same as it is reversed
func Check(s string) (b bool){
	a := Reverse(s)
	if s == a{
		b = true
	}else {
		b = false
	}
	return
}
gocrazygh

Palíndromo

function palindrome(str) {
	if (str.toLowerCase() === str.toString().toLowerCase().split('').reverse().join('')) {
		return true;
	} else {
		return false;
	}
}
Fierce Ferret

Palíndromo

import java.util.Scanner;
class Palindrome {
    public static void main(String args[]) {
        String original, reverse = "";
        Scanner s1 = new Scanner(System.in);
        System.out.println("Enter a word");
        original = "cat";
        int length = original.length();
        for ( int i = length - 1; i >= 0; i-- )
            reverse = reverse + original.charAt(i);
        if (original.equals(reverse))
            System.out.println("true");
        else
            System.out.println("false");
    }
}
Breakable Boar

Palíndromo

# Note: A palindrome is a string that reads the same forwards and backwards.
def palindrome_function(original_list, user_string):
    # reversing the list
    reversed_list = original_list[::-1]

    # comparing reversed_list to original_list to
    # determine if the original_list is a palindrome
    if reversed_list == original_list:
        print("'" + user_string.lower() + "' is a palindrome.")
    else:
        print("'" + user_string.lower() + "' is not a palindrome!")
        
        
def main():
    # promting user to input a word or phrase
    user_string = input("Enter string: ")
    
    user_list = list(user_string.lower())

	# putting our palindrome_function() to use
    palindrome_function(user_list, user_string)


if __name__ == "__main__":
    main()
Weary Warbler

Respostas semelhantes a “Palíndromo”

Perguntas semelhantes a “Palíndromo”

Procure respostas de código populares por idioma

Procurar outros idiomas de código