原文:

给定一个包含构成句子的单词的字符串(属于英语)。任务是输出输入句子的等价 ascii 句子。 一个句子的 ascii 形式是输入字符串的每个字符的转换,并将它们与字符串中出现的字符位置对齐 示例:

input : hello, world!
output : ascii sentence:
         104101108108111443211911111410810033
input : geeksforgeeks
output : ascii sentence:
         7110110110711510211111471101101107115

说明: 要完成任务,我们需要将每个字符转换成它的等价 。我们执行以下步骤来获得给定句子的等效 ascii 形式-

  • 遍历整个句子/字符串的长度
  • 一次取句子的每个字符,减去空字符,并显式地键入结果
  • 打印结果

按照上面的步骤,我们可以实现给定句子/字符串的等效 ascii 形式。

c

// c   implementation for converting
// a string into it's ascii equivalent sentence
#include 
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] - null;
        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);
    }
}

python 3

# 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 iss 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.

服务器端编程语言(professional hypertext preprocessor 的缩写)


java 描述语言


输出:

ascii sentence:
7110110110711510211111471101101107115

转换成等价 ascii 句子的时间复杂度是,其中 len 是字符串的长度。 应用:

  • 英语中的句子可以被编码/解码成这种形式,例如,将一个句子转换成它的等效 ascii 形式,并在每个数字上加 5,然后从编码器端发送出去。稍后,解码器可以从每个数字中减去 5,并将其解码为原始形式。这样,只有发送方和接收方能够解码句子。
  • ascii 形式也用于将数据从一台计算机传输到另一台计算机。

https://youtu.be/j8wgtk7i

-我们是 t0