每行都有一个单词和一个数字。我需要以某种方式选择第 n 个字母,它们一起组成一个新单词。例如:
and 3
for 3
map 2
wrestle 1
draw
Run Code Online (Sandbox Code Playgroud)
它必须这样开始
cat char.txt | ...
Run Code Online (Sandbox Code Playgroud)
而且我只允许使用 sed(不允许使用 awk、perl,...)。
我知道如何选择所有数字
sed 's/\(.*\) \(.*\)/\2/g'
Run Code Online (Sandbox Code Playgroud)
或文字
sed 's/\(.*\) \(.*\)/\1/g'
Run Code Online (Sandbox Code Playgroud)
我在想
cat char.txt | head -c $(sed 's/\(.*\) \(.*\)/\2/g') | tail -c 1 | sed 's/\n\//g'
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为它不会迭代所有行,并且由于某种原因它甚至无法在单行上工作。
请需要一些帮助和指导
泰
我正在阅读Spring 上的JPA 文档,并且正在尝试重组我的代码。
我现在拥有的:
布鲁尔存储库
@Repository
public class BrewerRepository {
@PersistenceContext(name = "vivesPU")
private EntityManager entityManager;
public List<Brewer> getAll() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
布鲁尔服务公司
@Service
public class BrewerService {
@Autowired
private BrewerRepository brewerRepository;
public List<Brewer> getAll() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
家庭控制器
@Controller
public class HomeController {
@Autowired
private BrewerService brewerService;
@GetMapping("/")
public String index(Model model) {
List<Brewer> brewers = this.brewerService.getAll();
model.addAttribute("brewers", brewers);
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
持久化JPAConfig
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories
public class PersistenceJPAConfig{
@Bean
public LocalContainerEntityManagerFactoryBean …Run Code Online (Sandbox Code Playgroud) 这是我的适配器类:
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
@Override
public LocalDateTime unmarshal(String v) throws Exception {
return new LocalDateTime(v);
}
@Override
public String marshal(LocalDateTime v) throws Exception {
return v.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个我想存储日期的对象类:
@XmlAccessorType(XmlAccessType.FIELD)
public class Object {
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime time;
public LocalDateTime getTime() {
return time;
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我无法编译它。表明问题出在return new LocalDateTime(v);。这是我得到的错误:
Error:(9, 16) java: constructor LocalDateTime in class java.time.LocalDateTime cannot be applied to given types;
required: java.time.LocalDate,java.time.LocalTime
found: java.lang.String
reason: actual and formal argument lists differ in …Run Code Online (Sandbox Code Playgroud) 我收到TypeError,但我不明白为什么。错误发生于c = t[i][0](根据调试器)。我有3个字符组(名单)g1,g2和g3我试图通过减去关键的改变字符的索引k1,k2或者k3从索引。我现在用于测试的内容:
text = 'abcd'
l_text = [('a', 0), ('b', 1), ('c', 2), ('d', 3)]
k1, k2, k3 = 2, 3, 1
Run Code Online (Sandbox Code Playgroud)
这是代码:
def rotate_left(text, l_text, k1, k2, k3):
i = 0
newstr = [None]*len(text)
for t in l_text: # t = tuple
c = t[i][0]
if c in g1: # c = char
l = int(l_text[i][1]) # l = index of the char in …Run Code Online (Sandbox Code Playgroud) 我想知道如何为具有特定值的PriorityQueue添加值.
我有一个Map<Integer, Integer> // element -> value
,我想elements优先插入PriorityQueue value.
例如:
Map{1=0, 3=5265, 5=22375, 7=4202, 9=233, 11=351, 13=119}
Run Code Online (Sandbox Code Playgroud)
应该在队列中有这个顺序:
{1, 13, 9, 11, 7, 3, 5}
Run Code Online (Sandbox Code Playgroud) 我这里有一些代码,我需要有人来解释它的作用.
fun :: (a -> Bool) -> [a] -> [a]
fun p [] = []
fun p (x:xs) = if (p x) then (x : fun p xs) else (fun p xs)
Run Code Online (Sandbox Code Playgroud)
我没有得到这个部分
a - >布尔
和
(PX)
所以代码遍历列表,如果它是空的,它返回一个空列表.如果列表不为空,则检查是否为空(p x).如果是,则保持元素不变并转到列表中的下一个元素,否则它将删除元素.