#34051: C++:AC


john1100729@gmail.com (靖諺)

學校 : 臺北市立中正高級中學
編號 : 191308
來源 : [122.100.69.45]
最後登入時間 :
2024-02-02 19:22:52
f514. 拼字遊戲 (Spelling) -- TOI練習賽202012新手組第2題 | From: [122.100.70.22] | 發表日期 : 2023-02-25 21:49

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

int main()
{
    int i, j, s, t;
    string S, T;
    
    cin >> S >> T;
    
    s = S.size();
    t = T.size();
    
    int Ss[s]={0}, Tt[t]={0}, n[t];
    
    for (i=0;i<s;i++)
        Ss[i] = S[i] - 'a';
        
    for (i=0;i<t;i++)
        Tt[i] = T[i] - 'a';
        
    for (i=0;i<t;i++)
        n[i] = -1;
    
    for (i=0;i<t;i++)
        for (j=0;j<s;j++)
            if (Tt[i] == Ss[j]) {
                n[i] = j;
                Ss[j] = -1;
                break;
            }
    
    for (i=0;i<t;i++) {
        if (n[i] != -1)
            cout << n[i] + 1 << " ";
        else
            cout << "X ";
    }
        
}

 
ZeroJudge Forum