懂哥的琐纪 2024-01-25 08:03 采纳率: 0%
浏览 7

Codeforces 1092C ——求解,求指正

题目链接:Problem - 1092C - Codeforces

C. Prefixes and Suffixes

我的思路:
1、提取出长度为(n-1)的子串,然后将其拼接出原串

2、判断子串能否成为 Prefixes

3、输出结果

WA代码:
(Wrong Answer on test 19)

#include <iostream>
#include <cstdio>
#include <string>
using namespace std ;

const int N = 1e4+10 ;
string ss , s[N] , maxx[N] ;
bool p[N] = { false } , judge[N]={ false };

int main()
{
    int n ;
    cin >> n ;
    for(int i=1 ; i<=2*n-2 ; ++i )  cin >> s[i] ;


    //特例:n = 2 时, PS
    if(n == 2){
        cout << "PS" << '\n' ;  return 0 ;
    }

    int flag = 0 ;
    for(int i=1 ; i<=2*n-2 ; ++i )
        if(s[i].size() == n-1)  maxx[++flag] = s[i] ;
    
    // 判断ss
    string mid = maxx[1].substr(1 , n-2) ;
    if(maxx[2].find(mid) == 0)   ss = maxx[1] + maxx[2][n-2] ;
    else    ss = maxx[2] + maxx[1][n-2] ;

    for(int i=1 ; i<=2*n-2 ; ++i )
        if(ss.find(s[i])==0 && !judge[s[i].size()]){
            judge[s[i].size()] = true ;
            p[i] = true ;
        }

    
    for(int i=1 ; i <= 2*n-2 ; ++i)
    {
        if(p[i])    cout << 'P' ;
        else    cout << 'S' ;
    }
    cout << '\n' ;

    system("pause") ;
    return 0 ;
}

临表涕零,感激不尽!

原文链接:https://blog.csdn.net/2301_79379567/article/details/135773364

  • 写回答

1条回答 默认 最新

  • 柯本 2024-01-26 08:51
    关注

    我测试了你的程序,例样全部通过的,最可能的问题是
    你的

       system("pause") ;
    

    绝对多余,考试系统一定不能用这个的。
    把它删除试试

    评论

报告相同问题?

问题事件

  • 创建了问题 1月25日

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源