Dada una string que contiene palabras que forman una oración (perteneciente al idioma inglés). La tarea es generar la oración ASCII equivalente a la oración de entrada.
La forma ASCII de una oración es la conversión de cada uno de los caracteres de la string de entrada y alinearlos en la posición de los caracteres presentes en la string.
Ejemplos:
Input : hello, world! Output : ASCII Sentence: 104101108108111443211911111410810033 Input : GeeksforGeeks Output : ASCII Sentence: 7110110110711510211111471101101107115
Explicación:
C++
// C++ implementation for converting // a string into it's ASCII equivalent sentence #include <bits/stdc++.h> using namespace std; // Function to compute the ASCII value of each // character one by one void ASCIISentence(std::string str) { int l = str.length(); int convert; for (int i = 0; i < l; i++) { convert = str[i]; cout << convert; } } // Driver function int main() { string str = "GeeksforGeeks"; cout << "ASCII Sentence:" << std::endl; ASCIISentence(str); return 0; }
Java
// Java implementation for converting // a string into it's ASCII equivalent sentence import java.util.*; import java.lang.*; class GeeksforGeeks { // Function to compute the ASCII value of each // character one by one static void ASCIISentence(String str) { int l = str.length(); int convert; for (int i = 0; i < l; i++) { convert = str.charAt(i); System.out.print(convert); } } // Driver function public static void main(String args[]) { String str = "GeeksforGeeks"; System.out.println("ASCII Sentence:"); ASCIISentence(str); } }
Python3
# Python3 implementation for # converting a string into it's # ASCII equivalent sentence # Function to compute the ASCII # value of each character one by one def ASCIISentence( str ): for i in str: print(ord(i), end = '') print('\n', end = '') # Driver code str = "GeeksforGeeks" print("ASCII Sentence:") ASCIISentence(str) # This code is contributed by "Sharad_Bhardwaj".
C#
// C# implementation for converting // a string into it's ASCII equivalent sentence using System; class GeeksforGeeks { // Function to compute the ASCII value // of each character one by one static void ASCIISentence(string str) { int l = str.Length; int convert; for (int i = 0; i < l; i++) { convert = str[i]; Console.Write(convert); } } // Driver function public static void Main() { string str = "GeeksforGeeks"; Console.WriteLine("ASCII Sentence:"); ASCIISentence(str); } } // This code is contributed by vt_m.
PHP
<?php // PHP implementation for converting a // string into it's ASCII equivalent sentence // Function to compute the ASCII // value of each character one by one function ASCIISentence($str) { for ($i = 0; $i< strlen($str); $i++) echo ord($str[$i]); } // Driver code $str = "GeeksforGeeks"; echo "ASCII Sentence:"."\n"; ASCIISentence($str); // This code is contributed // by ChitraNayal ?>
Javascript
<script> // Javascript implementation for converting // a string into it's ASCII equivalent sentence // Function to compute the ASCII value of each // character one by one function ASCIISentence(str) { let l = str.length; let convert; for (let i = 0; i < l; i++) { convert = str[i].charCodeAt(0); document.write(convert); } } // Driver function let str = "GeeksforGeeks"; document.write("ASCII Sentence:<br>"); ASCIISentence(str); // This code is contributed by rag2127 </script>