1
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 その199

Last updated at Posted at 2025-07-06

概要 

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

練習問題

atcoderを解け。
ABC 085 C - Otoshidama
10000円札、5000円札、1000円札がある前提で、合計がN枚、Y円になる組み合わせを求める。

in

9 45000

out

0 9 0 or 4 0 5

サンプルコード


module test;
	integer stdin = 'h8000_0000;
	integer n,
		a,
		b,
		c,
		ch,
		i,
		j,
		k,
		n,
		p,
		v;
	reg [7:0] pc;
	always #1
	begin
		case(pc)
		10:
		begin
			ch = $fscanf(stdin, "%d", n);
			pc <= 20;
		end
		20:
		begin
			ch = $fscanf(stdin, "%d", p);
			pc <= 30;
		end
		30:
		begin
			//$display(" %d%d", n, p);
			pc <= 40;
		end
		40:
		begin
			for (i = 0; i < n; i = i + 1)
			begin
				for (j = 0; j < n - i; j = j + 1)
				begin
					k = n - i - j;
					v = 10000 * i + 5000 * j + 1000 * k;
					if (v == p)
					begin
						a = i;
						b = j;
						c = k;
					end
				end
			end
			pc <= 60;
		end
		60:
		begin
			$write("%d %d %d", a, b, c);
			pc <= 70;
		end
		70:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		pc <= 10;
		v = 0;
		b = 0;
		c = 0;
		p = 0;
	end
endmodule


実行結果

>vvp a.out
9 45000
          4           0           5

以上。

1
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
1
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?