×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

C program - strings..

Write a program that reads from standard input (using getchar).
The first time a word appears in the text, it is left as is, but a unique number (starting with 0, then 1, etc.) is associated with it. For all subsequent occurrences of the word, it is replaced by its number.
for example:

To be or not to be
Or not to be or to be

would become:

To be or not to 1
Or 3 4 1 2 4 1

Note that spacing and line breaks have been preserved.
You may assume that there are at most 80 characters in any line.
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / C program - strings..
    Write a program that reads from standard input (using getchar).
    The first time a word appears in the text, it is left as is, but a unique number (starting with 0, then 1, etc.) is associated with it. For all subsequent occurrences of the word, it is replaced by its number.
    for example:

    To be or not to be
    Or not to be or to be

    would become:

    To be or not to 1
    Or 3 4 1 2 4 1

    Note that spacing and line breaks have been preserved.
    You may assume that there are at most 80 characters in any line.
    • the process need a big table to store the index of word that is new to the table, it can be as big as a dictionary. What's the point of this question? to test the searching speed or the usage of memory?
      • i know.. it's really hard...