UVA_10391: Compound Words

本文详细阐述了如何使用字符数组、映射表和循环结构实现字符串的分段匹配及验证,通过实例演示了字符串处理的基本算法流程。

分析:读取所有字符串到字符数组中并存在map中建立映射,之后进入主循环,遍历每个字符串,按长度截取成两个字符串,分别在map中查找,如果找到了说明可以拆,进行下一个,不能继续找。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>

using namespace std;
char words[120010][30];
map<string,int> wmap;

int main()
{
	int n=0;
	while(~scanf("%s",words[n]))
	{
		wmap[words[n]]=1;
		n++;
	}

	for(int i=0; i<n; i++)
	{
		int len = strlen(words[i]);
		for(int j=0; j<len; j++)
		{
			char t1[30] = {0};
			char t2[30] = {0};
			strncpy(t1,words[i],j);
			strncpy(t2,words[i]+j,len-j);
			if(wmap[t1] && wmap[t2]){printf("%s\n",words[i]);break;}
		}
	}

    return 0;
}


/home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:435:35: error: ‘std_srvs::Trigger’ has not been declared bool relocalizeCallback(std_srvs::Trigger::Request &req, ^~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:435:53: error: ‘req’ was not declared in this scope bool relocalizeCallback(std_srvs::Trigger::Request &req, ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:436:35: error: ‘std_srvs::Trigger’ has not been declared std_srvs::Trigger::Response &res) ^~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:436:54: error: ‘res’ was not declared in this scope std_srvs::Trigger::Response &res) ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:436:54: note: suggested alternative: ‘read’ std_srvs::Trigger::Response &res) ^~~ read /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:436:57: error: expression list treated as compound expression in initializer [-fpermissive] std_srvs::Trigger::Response &res) ^ oryxbot_cruise_ex/CMakeFiles/oryxbot_cruise_ex_node.dir/build.make:62: recipe for target 'oryxbot_cruise_ex/CMakeFiles/oryxbot_cruise_ex_node.dir/src/oryxbot_cruise_ex.cpp.o' failed make[2]: *** [oryxbot_cruise_ex/CMakeFiles/oryxbot_cruise_ex_node.dir/src/oryxbot_cruise_ex.cpp.o] Error 1 CMakeFiles/Makefile2:6916: recipe for target 'oryxbot_cruise_ex/CMakeFiles/oryxbot_cruise_ex_node.dir/all' failed make[1]: *** [oryxbot_cruise_ex/CMakeFiles/oryxbot_cruise_ex_node.dir/all] Error 2 Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j8 -l8" failed
最新发布
06-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值