爱问知识人 爱问教育 医院库

C语言测试题一

首页

C语言测试题一

 [Problem] Please write C program according to the following condition(Test time : 4hours)

【问题】请根据以下条件写出C程序(测试时间:4小时)
There is Morse code which consists of ‘0’s and ‘1’s as a bitstream. This code starts with 1 as start-bit, which follows 8 data-bit with 1 or 0, ends with 0 as stop-bit. Find the rule as follows.
这就是摩斯码,包含0和1的比特序列;这种编码以“1”作为起始位开始,后面跟随8位“0”或者“1”,最后以“0”结束;可以从以下找到规则;

 

In the below example, between the start-bit and stop-bit, there are 8 data-bit,0 0 1 0 1 0 1 1. We can convert this data-bit into decimal number, the result is 43.
在下面的例子中,在开始位和结束位中间;共有8位数字:00101011;我们可以把他转换为10进制数字为43;

 
Example) Binary digit 00101011 (Decimal: 43)

Following these two steps, write a program which returns the result.
按照下面两步,写出程序返回结果;

Step 1) There is 10,000 bit stream in main.cpp. Find the Morse code from the beginning of bit stream to end and convert the binary digit into decimal number. (Check it from data[0] to data[9999] sequentially)
步骤1)在main.cpp中有个10,000的比特流;从开始位到结束位找出摩斯码;并且把二进制数字(我个人觉得是中间八位)转换为10进制数字;(依次从data[0]到data[999]检查)

Step 2) The converted decimals has the range from 0 to 255.Calculate the frequency of the decimal numbers and returns the number which has higher frequency among 256 numbers. If there are tie, return the larger number.
步骤2) 转换完之后的数字范围从0到255.计算出十进制数字的频率,并且返回256个数字中频率最高的;如果有相当的,就返回较大的数字;

Note) Below 30 bit stream, there are two Morse code,1000111110and1100011110, which converts into 31 and 143
注意)下面30为数字中,有两个摩斯码,1000111110and1100011110转换成十进制为 31和 143

 1110
[Implementation Function]

Int test_main(int data[SIZE]);

Return: the number of higher frequency (0~255, if there are tie, result should be the larger number.)


[Attachment 1 – single_id.cpp]

// DD NOT INCLUDE ANY FILES

#defineSIZE 10000

inttest_main(intdata[SIZE])
{
  return 0;  // the number of higher frequency
}


[Attachement 2 – main.cpp]

#include<stdio.h>
#include<stdlib.h>

#defineSIZE 10000

inttest_main(intdata[SIZE]);

static int data[SIZE];

void build_data(void)
{
  for (intc = 0; c<SIZE; c++)
    data[c] = rand() % 2;

}

voidmain(intargc, char* argv[])
{
  for (intl = 0; l< 10; l++)
  {
    build_data();

    printf("%d\n", test_main(data));
  }
}

提交回答

全部答案

类似问题

换一换
  • 软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):