题解 | #不重叠序列检测#

不重叠序列检测

https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,

	output reg match,
	output reg not_match
);

reg [2:0]cnt;
always@(posedge clk or negedge rst_n)
	if (rst_n == 1'b0)
		cnt <= 3'b0;
	else if (cnt == 3'd5)
		cnt <= 3'b0;
	else
		cnt <= cnt + 1'b1;

reg [5:0]data_reg;
always@(posedge clk or negedge rst_n)
	case(cnt)
		3'd0 : data_reg[0] <= data;
		3'd1 : data_reg[1] <= data;
		3'd2 : data_reg[2] <= data;
		3'd3 : data_reg[3] <= data;
		3'd4 : data_reg[4] <= data;
		3'd5 : data_reg[5] <= data;
		default : data_reg <= 6'b0;
	endcase

always@(posedge clk or negedge rst_n)
	if (rst_n == 1'b0)
		begin
			match <= 1'b0;
			not_match <= 1'b0;
		end
	else if (cnt == 3'd5)
		begin
			if (data_reg == 6'b00_1110)
				begin
					match <= 1'b1;
					not_match <= 1'b0;
				end
			else
				begin
					match <= 1'b0;
					not_match <= 1'b1;
				end
		end
	else
		begin
			match <= 1'b0;
			not_match <= 1'b0;
		end
			
endmodule

为什么我自测运行显示“您的程序未能在规定时间内运行结束,请检查是否循环有错或算法复杂度过大。”,但是提交后可以通过???

全部评论

相关推荐

迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务