60求调

P10836 『FLA - I』歌静河

zzh1109 @ 2024-08-08 14:31:48


#include<bits/stdc++.h>
using namespace std;
int n,m,cc,aa;
string a,b;
queue<int>a1;
queue<int>a2;
int main(){
    cin>>n>>m;
    cin>>a>>b;
    for(int i=0;i<n;i++){
        if(a[i]=='#'){
            a1.push(i);
        }
        if(b[i]=='#'){
            a2.push(i);
        }
    }
    for(int i=0;i<m;i++){
        cc=(i%26)+1;
        if(!a1.empty()){
            aa=a1.front();
            a[aa]='a'+cc-1;
            a1.pop();
        }
        else if(!a2.empty()){
            aa=a2.front();
            b[aa]='a'+cc-1;
            a2.pop();
        }
    }
    cout<<a;
    return 0;
}

by byf2011 @ 2024-08-08 14:48:00

@zzh1109

可以这样写:

#include<bits/stdc++.h>
using namespace std;

int n, m;
char s[200002], s2[200002];
char ls = 'a';
int l2;
int g;
int id, f;

int main()
{
    cin >> n >> m >> s >> s2;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '#' && f == 0)
        {
            id = i;
            f = 1;
        }
        if (s2[i] == '#')
            l2++;
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i] != '#')
            cout << s[i];
        else if (s[i] == '#')
        {

            if (i == id)
            {
                g++;
                ls = 'a';
                cout << ls;
                continue;
            }
            if (l2 + g >= 26)
            {
                l2 -= (26 - g), g = 1, ls = 'a';
                cout << ls;
            }
            else
            {
                g++;
                ls = 'a' + (g - 1) % 26;
                cout << ls;
            }

        }
    }
    return 0;
}

求关注!!!

QAQ

by zzh1109 @ 2024-08-08 14:50:06

@byf2011 感谢大佬已关


by ATION001 @ 2024-10-17 10:05:06

不是你们光给个代码谁看得懂啊,还求关,干嘛不让别人直接去看题解?


|