zoj_1170
2011-10-03 01:36
113 查看
嗯嗯,开csdn博以后写的第三篇博文。。今天的任务勉强算完成了吧。。不知道明天能不能早点起床呢~
发现JOHN_BUG的开博提议很不错呵~
发现JOHN_BUG的开博提议很不错呵~
/* zoj_1170 字符串处理 简单题。一开始以为是要匹配出最长的连续公共子序列。写完后才发现不用那么复杂。。 方法:记录两个字符串开始匹配的首位置就行了。然后一个一个匹配就好了。 */ #include <iostream> #include <cstdio> #include <string> using namespace std; string a,b; int check( int i,int j ) { int len,len1,len2; len1=a.size(); len2=b.size(); len=0; while( i<len1 && j<len2 ) { if( a[i]==b[j] ) { len++; } i++; j++; } return len; } void output( int up,int down ) { int t1,t2,temp; if( up==0 ) { cout<<"appx("<<a<<","<<b<<") = 0\n"; return; } if( up==down ) { cout<<"appx("<<a<<","<<b<<") = 1\n"; return; } if( up>down ) { t1=up; t2=down; } else { t1=down; t2=up; } while( t2!=0 ) //求最大公约数喽 { temp=t1%t2; t1=t2; t2=temp; } up/=t1; down/=t1; cout<<"appx("<<a<<","<<b<<") = "<<up<<"/"<<down<<endl; } int main() { int maxi,t,i; while( cin>>a && a!="-1" ) { cin>>b; maxi=-1; for( i=0;i<b.size();i++ ) //两个字符串首位置的选择 { if( maxi<( t=check( 0,i ) ) ) maxi=t; } for( i=1;i<a.size();i++ ) { if( maxi<( t=check( i,0 ) ) ) maxi=t; } output( 2*maxi,a.size()+b.size() ); } return 0; }
相关文章推荐
- ZOJ 1170 String Matching
- ZOJ-1170
- zoj 1733【最长公共子序列DP】
- ZOJ 3471 Most Powerful(DP + 状态压缩)
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
- POJ 1170 多重DP 无状态压缩解法
- zoj1813水题
- ZOJ 2016 欧拉路判定
- ZOJ 3329 One Person Game 概率dp 处理环
- ZOJ 3811 dfs&并查集
- zoj 1000【a+b】
- zoj 1730 / poj 1455 Crazy Tea Party
- zoj 2900 dp or 线段树
- zoj Lunch Time 3875
- ZOJ 2588
- ZOJ 3195 Design the city (在线LCA,4级)
- ZOJ 1654 Place the Robots DINIC
- ZOJ 3499 M - Median
- ZOJ 2812 Quicksum
- zoj - 3037 - Ladies' Choice(稳定婚姻)