我正在尝试测试我的作业(背包问题),并且每次重新编译时都会重复输入所有这些输入。
这就是我所拥有的:
will@will-mint ~/code/byun-sp15 $ g++ knapsack.cpp
will@will-mint ~/code/byun-sp15 $ ./a.out
Please enter number of items: 3
Please enter Knapsack Capacity: 10
Enter weights and values of 3 items:
Item 1: 3 40
Item 2: 2 10
Item 3: 5 50
0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 *
0 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 *
0 * 50 * 50 * 99 * 50 * 50 * 60 * 60 * 60 * 60 *
显然我的桌子不正确,请不要帮助我。没有掠夺者!
我将3 10 3 40 2 10 5 50
放在test.txt中并尝试以下操作:
will@will-mint ~/code/byun-sp15 $ vim test.txt
will@will-mint ~/code/byun-sp15 $ test.txt > ./a.out
test.txt: command not found
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out >> output.log
will@will-mint ~/code/byun-sp15 $ vim output.log
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out 2> output.log
will@will-mint ~/code/byun-sp15 $ vim output.log
will@will-mint ~/code/byun-sp15 $ ./a.out < test.txt
will@will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out > output.log
will@will-mint ~/code/byun-sp15 $ vim output.log
will@will-mint ~/code/byun-sp15 $ ./a.out << test.txt
其中没有一个有效。我需要帮助我的bash-fu,如何在文本文件中使用一串空格分隔的数字作为我的a.out的输入?