UVA 10115 - Automatic Editing

本文介绍了一种基于字符串匹配的算法,用于实现文本中特定短句的自动替换功能。该算法通过逐字符比对的方式查找待替换短句,并完成替换过程。文章提供了完整的C++代码示例,展示了如何在给定的句子中按顺序替换指定短句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目大意:给出n个短句及其对应要改变后的短句。给出一句话,按顺序考虑所有短句以后,改变成的句子。

解题思路:句子从开头开始读取第一个短句的字符。每个位置开头都要试一次或者从字母与短句首字母一致开始试读短句长度的字符。如果读出来的字符串与短句一致。则改变句子。句子再从头开始,直到没有改变时,开始读第二个短句的字符。循环比较烦。。。

ac代码:

#include <iostream>
#include <cstring>
using namespace std;
string str, key[100], value[100], temp, temp2;
void search(int n)
{
	int i, j, k, len2=key[n].size();
	temp = "";
		for (i=0; i<str.size(); i++){
			if (str[i] == key[n][0] && i+len2-1 < str.size()){
				for (j=0; j<len2; j++)
					temp += str[i+j]; 
				if (temp == key[n]){
					for (j=0; j<i; j++)
						temp2 += str[j];
					temp2 += value[n];
					for (k=i+len2; k<str.size(); k++)
						temp2 += str[k];
					str = temp2;
					temp2 = "";
					i = -1;
				}
				temp = "";
			}
		}	
		
}
int main()
{
	int n, i, len;
	while (cin >> n && n != 0){
		getchar();
		for (i=0; i<n; i++){
			getline(cin, key[i]);
			getline(cin, value[i]);
		}
		getline(cin, str);
		len = str.size();
		for (i=0; i<n; i++)
			search(i);
		cout << str << endl;
	} 
	return 0;
}
### Minimal Bash-like Editing Issue Solution Minimal bash-like editing refers to a lightweight text editing mode that mimics the behavior of the Bash shell's command-line editor[^2]. This mode is often implemented in applications or terminals where users can perform basic editing tasks, such as navigating through text, deleting characters, and moving the cursor. Issues related to minimal bash-like editing typically involve incorrect keybindings, unexpected behavior during navigation, or problems with history management. To address issues with minimal bash-like editing, consider the following approaches: 1. **Keybinding Configuration**: Ensure that the keybindings for navigation and editing are correctly configured. For example, in many terminal emulators, the `Ctrl + A` and `Ctrl + E` shortcuts move the cursor to the beginning and end of the line, respectively. If these shortcuts do not work as expected, check the configuration file for the application or terminal emulator being used[^3]. 2. **Input Mode Settings**: Some applications allow switching between different input modes, such as Emacs and Vi. Verify that the correct input mode is selected. For instance, in certain environments, you can toggle between modes using commands like `set -o vi` or `set -o emacs`[^4]. 3. **Terminal Compatibility**: Ensure that the terminal emulator is compatible with the application requiring bash-like editing. Incompatibilities may arise if the terminal does not support specific escape sequences or control characters required for proper editing functionality[^5]. 4. **Environment Variables**: Check environment variables such as `EDITOR` or `VISUAL` to ensure they point to the desired editor. Additionally, verify that the `TERM` variable is set correctly for your terminal type[^6]. Below is an example of configuring keybindings in a `.inputrc` file for bash-like editing: ```bash # ~/.inputrc "\e[A": history-search-backward "\e[B": history-search-forward ``` This configuration enables searching through command history using the up and down arrow keys while typing a prefix[^7].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值