点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 金牌教程 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

From sina007
斜角2
讨论 Discussion
 
斜角2的题解
#include<bits/stdc++.h>
using namespace std;

int main(){
freopen("p1721.in","r",stdin);
freopen("p1721.out","w",stdout);
int n,i,j,k,x,a[11][11]={0};
cin>>n;
//填矩阵左上角一半
for(k=1;k<=n;k++){
i=k;
for(j=1;j<=k;j++){
a[i][j]=k;
i--;
}
}
//填矩阵右下角一半
for(k=n;k>=1;k--){
j=n+1-k;i=n;
for(x=1;x<=k;x++){
a[i][j]=k;
j++;
i--;
}
}
//打印整个矩阵
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)cout<<setw(3)<<a[i][j];
cout<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
( )

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
short a[100][100]={0},i,j,k=0,n;
cin>>n;
for(k=1;k<=n;k++){
for(i=1;i<=k;i++)a[i][n+1-k]=k;
for(j=n+1-k;j<=n;j++)a[k][j]=k;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)cout<<setw(3)<<a[i][j];
cout<<endl;
}
return 0;
}#include<iostream>
#include<iomanip>
using namespace std;
int main(){
short a[100][100]={0},i,j,k=0,n;
cin>>n;
for(k=1;k<=n;k++){
for(i=1;i<=k;i++)a[i][n+1-k]=k;
for(j=n+1-k;j<=n;j++)a[k][j]=k;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)cout<<setw(3)<<a[i][j];
cout<<endl;
}
return 0;#include<iostream>
#include<iomanip>
using namespace std;
int main(){
short a[100][100]={0},i,j,k=0,n;
cin>>n;
for(k=1;k<=n;k++){
for(i=1;i<=k;i++)a[i][n+1-k]=k;
for(j=n+1-k;j<=n;j++)a[k][j]=k;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)cout<<setw(3)<<a[i][j];
cout<<endl;
}
return 0;
}
}#include<iostream>
#include<iomanip>
using namespace std;
int main(){
short a[100][100]={0},i,j,k=0,n;
cin>>n;
for(k=1;k<=n;k++){
for(i=1;i<=k;i++)a[i][n+1-k]=k;
for(j=n+1-k;j<=n;j++)a[k][j]=k;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)cout<<setw(3)<<a[i][j];
cout<<endl;
}
return 0;
}
( )
ddd
#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}#include<iostream>
#include<string>

using namespace std;

int dp[1001][1001], n, m;
string a, b;

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
freopen("p1513.in", "r", stdin);
freopen("p1513.out", "w", stdout);

getline(cin, a);
getline(cin, b);

n = a.size();
m = b.size();

for(int i = n;i >= 1;i --) {
for(int j = m;j >= 1;j --) {
if(a[i] == b[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}

int max = dp[1][1];
int st = 1;

for(int i = 1;i <= n;i ++) {
for(int j = 1;j <= m;j ++) {
if(dp[i][j] > max) {
st = i;
max = dp[i][j];
}
}
}

  for(int i = 0;i < max;i ++) {
   cout << a[st + i];
}

fclose(stdin);
fclose(stdout);

return 0;
}
( )
发布讨论主题 回复讨论主题
Flag
  
题号
  P1721
  模拟
通过
  44人
提交
  180次
通过率
  24%
难度
  0
提交 讨论 题解
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1242 | Online Users / Processes : 0 / 71 | Processed Time : 441 ms | Server Time : 2025/4/27 17:45:37