测试点#5#7wa,下载下来本地过了,但洛谷上过不了
查看原帖
测试点#5#7wa,下载下来本地过了,但洛谷上过不了
1484547
niukou123__楼主2025/7/25 19:23

#5 程序输出的和下载下来的答案数据一致,但是wa了

代码如下

#include <iostream>
#include <algorithm>
using namespace std;
void work(int p1,int p2,int p3,string word,int count){  
    int start=0;
    int end; 
    for(int i=0;i<word.length();i++){  
        if(word[i]=='?'){
            count--;
            char unit='\0';
            string add="";
            int len=word[i+1]-word[i-1]-1;
            for(int k=1;k<=len;k++){
                unit=word[i-1]+k;
                if(p1==2&&word[i-1]>=97){unit=toupper(unit);}
                else if(p1==3){unit='*';}
                for(int j=0;j<p2;j++){                  
                    add.push_back(unit);
              }
              
            }
            if(p3==2)reverse(add.begin(),add.end());           
            end=i;
            for(int x=start;x<end;x++)cout<<word[x];
            start=end+1;
            cout<<add;
        }
        else if(count==0){
            for(int y=i;y<word.length();y++){
                cout<<word[y];
                
            }
            return;
        }
    }




}
int main(){
    int p1,p2,p3;
    cin>>p1>>p2>>p3;
    string word;
    cin>>word;
    //预处理
    int count=0;
    for(int i=0;i<word.length();i++){
        if(word[i]=='-'){
            if(word[i+1]-word[i-1]==1){
                word.replace(i,1,"");
            }
            else if(
                (word[i-1]>=65&&word[i+1]>=65&&word[i+1]>word[i-1])||
                (word[i-1]<65&&word[i+1]<65&&word[i+1]>word[i-1])
            ){
                word.replace(i,1,"?");
                count++;
            }
        }
    }
    work(p1,p2,p3,word,count);
    return 0;
}
2025/7/25 19:23
加载中...