×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

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