⬆︎
×

[PAT-A] 1084 Broken Keyboard

Hyplus目录

Java

package PAT_A1084_Broken_Keyboard;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        boolean[] st = new boolean[210];

        b += '#';
        int j = 0;
        for (int i = 0; i < a.length(); i++) {
            char x = Character.toUpperCase(a.charAt(i));
            char y = Character.toUpperCase(b.charAt(j));
            if (x == y) {
                j++;
            } else if (!st[x]) {
                System.out.print(x);
                st[x] = true;
            }
        }

        sc.close();
    }
}

C++

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

string a, b;
bool st[210];

int main() {
    cin >> a >> b;

    b += '#';
    for (int i = 0, j = 0; i < a.size(); i++) {
        char x = toupper(a[i]), y = toupper(b[j]);
        if (x == y) j++;
        else if (!st[x]) {
            cout << x;
            st[x] = true;
        }
    }

    return 0;
}

发表评论