
在systemverilog中调用如下文件
file.txt
内容
addr 12345678
data aa55aa55
attri cececece
并把这种索引对内存在一个hash函数h_array[string]中.

在读入后,再枚举一次函数verilog fscanf,通过打印测试能否读取成功。
相关代码如下:
program file_read;
integer file;
string variable;
reg [31:0] value;
reg [31:0] h_array [string] ;

initial
begin:file_block
file=$fopen("file.txt","r");
if (file == 0)
disable file_block;
while(!$feof(file))
begin

$fscanf(file,"%s %h\n",variable,value);
h_array[variable] = value;
end
$fclose(file);
//check read result.
foreach (h_array[i])
begin

table[index] = new hashmapentry(key, value, hash, table[index])ql[i].subresult[index].value = ql[i-1].subresult[j].value + goods[i-1].value), i’ll give you two other positive integers a and b, and you need to find out all the answers for n=a, n=a+1, …, n=b.inputthe input contains at most 25 test cases. each test case begins with 3 integers a, b and c, where c is the number of lost cards. the next line contains c strings, representing the lost cards. each card is formatted as values, valueh, valuec or valued, where value is a composite integer. no two lost cards are the same. the input is terminated by a=b=c=0. there will be at most one test case where a=1, b=50,000 and c<=10,000. for other test cases, 1<=a<=b<=100, 0<=c<=10.outputfor each test case, print b-a+1 integers, one in each line. since the numbers might be large, you should output each integer modulo 1,000,000. print a blank line after each test case.sample input12 20 24s 6h0 0 0 output for the sample input000000103湖南省第七届大学生计算机程序设计竞赛 the seventh hunan collegiate programming contestproblem krmq with shiftsin the traditional rmq (range minimum query) problem, we have a static array a. then for each query (l, r) (l<=r), we report the minimum value among a[l], a[l+1], …, a[r]. note that the indices start from 1, i.e. the left-most element is a[1].in this problem, the array a is no longer static: we need to support another operation shift(i1, i2, i3, …, ik) (i11): we do a left “circular shift” of a[i1], a[i2], …, a[ik].for example, if a={6, 2, 4, 8, 5, 1, 4}, then shift(2, 4, 5, 7) yields {6, 8, 4, 5, 4, 1, 2}. after that, shift(1,2) yields {8, 6, 4, 5, 4, 1, 2}.inputthere will be only one test case, beginning with two integers n, q (1<=n<=100,000, 1<=q<=120,000), the number of integers in array a, and the number of operations. the next line contains n positive integers not greater than 100,000, the initial elements in array a. each of the next q lines contains an operation. each operation is formatted as a string having no more than 30 characters, with no space characters inside. all operations are guaranteed to be valid. warning: the dataset is large, better to use faster i/o methods.outputfor each query, print the minimum value (rather than index) in the requested range.sample inputoutput for the sample input7 56 2 4 8 5 1 4query(3,7)shift(2,4,5,7)query(1,4)shift(1,2)query(2,2)146ranknamesolvedtimeabcdefghijktotal1长沙雅礼中学西雅浮云队96591/11/71/231/1531/101/741/951/--0/--2/2301/4611/92长沙雅礼中学东雅神马队98771/51/62/326/1851/141/811/600/--1/2740/--1/10015/93湘潭大学饕餮911621/01/71/674/2681/171/1415/715/2700/--0/--1/10120/94湖南师大附中dream181988841/61/371/311/2641/141/2104/1720/--0/--0/--1/9011/85国防科技大学alpc-hnpt289821/11/111/312/2471/341/1129/2960/--0/--0/--1/7017/86长郡中学骨肉相连队810411/01/52/310/--1/232/1219/2550/--1/2410/--2/14519/87长沙雅礼中学南雅超速队813401/21/151/456/2841/203/19018/1950/--0/--0/--1/10932/88中南大学小白菜74822/22/121/481/--1/151/1621/1240/--0/--0/--1/7910/79湖南师大附中vijos64432/61/51/830/--1/181/2588/--0/--0/--0/--1/5315/610长沙雅礼中学北雅极限队64771/11/126/1220/--1/61/1939/--0/--0/--0/--1/4320/611长沙市一中imba64901/71/162/1000/--1/311/14511/--0/--0/--0/--4/11121/612湖南省衡阳市第八中学八中水上乐园66421/82/312/670/--1/354/2658/--0/--0/--0/--1/13619/613湘潭大学貔貅66541/111/132/1140/--1/253/23013/--0/--0/--0/--1/20122/614湖南省衡阳市第八中学完美世界66611/32/192/810/--1/311/2675/--0/--0/--0/--1/22013/615湖南师范大学 smile66771/32/511/1500/--1/241/2322/--0/--0/--0/--1/1979/616湖南工业大学luckycoding66911/01/131/720/--1/367/2830/--0/--0/--1/--1/16713/617湖南省衡阳市第八中学默默向上游68091/11/402/1610/--2/515/2345/--0/--0/--0/--2/18218/618长沙学院长大1队68641/12/234/1160/--1/381/24212/--0/--0/--0/--6/26427/619国防科技大学alpc-hnpt768991/01/294/1580/--1/227/--8/2760/--0/--0/--1/21423/620怀化学院bluebird69021/21/1014/1990/--2/301/2463/--0/--0/--0/--1/13523/621国防科技大学alpc-hnpt5610581/11/1114/2670/--1/232/20921/--0/--0/--0/--3/22743/622长郡中学uracil队615322/92/284/1500/--1/380/--38/2880/--0/--0/--3/13950/623湖南大学corecoder53321/11/161/680/--1/340/--48/--0/--0/--0/--1/21353/524长沙理工大学is_soy53583/141/291/500/--1/911/--0/--0/--0/--0/--1/1348/525国防科技大学alpc-hnpt353672/81/121/1120/--1/154/--12/--0/--0/--0/--1/20022/526湖南大学acmen53741/41/243/1130/--1/345/--0/--0/--0/--0/--1/15912/527湖南商学院overpowering54221/11/252/2100/--1/450/--0/--0/--0/--0/--1/1216/528中南大学scarletf554431/01/102/800/--2/291/2841/--0/--0/--0/--10/--18/529中南大学wickedsick54691/11/161/920/--1/443/--0/--0/--0/--0/--6/21613/530长郡中学mars队54861/21/251/910/--1/430/--9/--0/--0/--0/--4/26517/531长郡中学aq队55151/361/923/1980/--1/370/--16/--0/--0/--0/--1/11223/532湖南文理学院a+b55351/41/322/980/--1/1190/--0/--0/--0/--0/--2/2427/533湖南师范大学xiangcai55711/72/251/550/--1/760/--6/2880/--0/--0/--0/--11/534南华大师范大学 banana43252/71/492/1650/--1/640/--0/--0/--0/--0/--1/--7/451湖南城市学院codekiller43371/171/562/1850/--1/590/--0/--0/--0/--0/--3/--8/452长沙学院长大2队43421/32/444/1560/--1/590/--0/--0/--0/--0/--5/--13/453中南林业科技大学beta43541/01/174/2130/--2/440/--0/--0/--0/--0/--8/--16/454怀化学院cyandragon43612/51/3713/--0/--1/490/--0/--0/--0/--0/--3/21020/455湖南工学院湖工4队43771/61/231/1260/--3/1820/--2/--0/--0/--0/--2/--10/456湖南理工学院wa_lions43782/21/191/1410/--2/1760/--0/--0/--0/--0/--6/--12/457长沙学院长大3队43852/91/283/2150/--1/730/--0/--0/--0/--0/--7/--14/458长郡中学随便队43951/53/771/1490/--3/846/--0/--0/--0/--0/--7/--21/459湖南第一师范学院一师一队43961/32/701/2080/--1/950/--0/--0/--0/--0/--3/--8/460湖南城市学院bydream44032/121/451/2040/--2/1020/--0/--0/--0/--0/--1/--7/461湖南人文科技学院wecana4072/52/412/1810/--2/1000/--0/--0/--0/--0/--13/--21/462长沙理工大学超越队44642/181/333/2820/469湖南工学院湖工2队46153/421/691/2430/--1/2210/--0/--0/--0/--0/--0/--6/470湖南农业大学东方科技学院orient246161/71/796/2850/--1/1450/--0/--0/--0/--0/--0/--9/471长沙民政职业技术学院westcows46361/22/408/--0/--6/2020/--0/--0/--0/--0/--1/27218/472长沙学院长大4队46467/112/1441/2400/--2/910/--0/--0/--0/--0/--0/--12/473湖南理工学院南湖学院lucifer47173/273/2093/2570/--1/1040/--0/--0/--0/--0/--0/--10/474湖南科技学院crazy48091/71/2822/2750/--1/790/--0/--0/--0/--0/--0/--25/475湖南工业大学prometheus48461/26/1945/2800/--3/1500/--0/--0/--0/--0/--1/--16/476湖南商学院onepiece3951/11/2411/--0/--2/500/--0/--0/--0/--0/--7/--22/377湖南商学院ablaze31041/01/3310/--0/--1/710/--0/--0/--0/--0/--0/--13/378湖南工学院湖工1队31121/141/317/--0/--1/670/--5/--0/--0/--0/--5/--20/379长沙市一中老干爹31181/21/196/--0/--3/570/--11/--0/--0/--0/--0/--22/380湖南人文科技学院tammer31281/02/1821/--0/--2/700/--0/--0/--0/--0/--4/--30/381怀化学院whitetiger31291/111/699/--0/--1/490/--0/--0/--0/--0/--0/--12/382湖南科技大学中原一点红31302/172/589/--0/--1/150/--10/--0/--0/--0/--0/--24/383中南林业科技大学tryourbest31311/71/374/--0/--1/870/--0/--0/--0/--0/--0/--7/384湖南文理学院flag31321/11/1412/--0/--4/570/--0/--0/--0/--0/--5/--23/385中南林业科技大学gamma31341/31/368/--0/--1/950/--0/--0/--0/--0/--0/--11/386湖南科技学院极时雨31351/01/260/--0/--1/1090/--0/--0/--0/--0/--0/--3/387邵阳学院大熊猫31433/102/348/--0/--1/390/--0/--0/--0/--0/--0/--14/388湖南农业大学shinelong131461/12/3210/--0/--1/932/--0/--0/--0/--0/--0/--16/389湖南农业大学shinelong331601/31/259/--0/--3/920/--0/--0/--0/--0/--5/--19/390长沙医学院哈里波特731631/151/745/--0/--1/741/--0/--0/--0/--0/--1/--10/391湖南科技大学crazier&apos
end
end
endprogram
用vcs编译后verilog fscanf,运行,输出如下结果
hash index addr value 12345678
hash index attri value cececece
hash index data value aa55aa55
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-133239-1.html
o