0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsでiverilog その174

Posted at

概要 

windowsでiverilogやってみた。
練習問題、やってみた。

練習問題

AtCoderを解け。
500円玉、100円玉、50円玉を使ってXX円を支払う方法が何通りあるかを求める。

サンプルコード


module test;
	integer stdin = 'h8000_0000;
	integer x,
		i,
		j,
		k,
		a,
		b,
		c,
		ch,
		v,
		p;
	reg [7:0] pc;
	initial
	begin
		pc <= 10;
		v = 0;
		p = 0;
	end
	always #1
	begin
		case(pc)
		10:
		begin
			ch = $fscanf(stdin, "%d%d%d%d", a, b, c, x);
			pc <= 20;
		end
		20:
		begin
			i = 0;
			pc <= 30;
		end
		30:
		begin
			if (i < a + 1)
			begin
				pc <= 40;
			end
			else
			begin
				pc <= 110;
			end
		end
		40:
		begin
			j = 0;
			pc <= 50;
		end
		50:
		begin
			if (j < b + 1)
			begin
				pc <= 60;
			end
			else
			begin
				pc <= 100;
			end
		end
		60:
		begin
			k = 0;
			pc <= 70;
		end
		70:
		begin
			if (k < c + 1)
			begin
				pc <= 80;
			end
			else
			begin
				pc <= 90;
			end
		end
		80:
		begin
			//$write("%d%d%d", i, j, k);
			if (500 * i + 100 * j + 50 * k == x)
			begin
				p++;
			end
			k++;
			pc <= 70;
		end
		90:
		begin
			j++;
			pc <= 50;
		end
		100:
		begin
			i++;
			pc <= 30;
		end
		110:
		begin
			$write("%d", p);
			pc <= 120;
		end
		120:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		//$monitor(" %d", pc);
	end
endmodule




実行結果

>vvp a.out
2
2
2
100
          2

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?