PATB1033古いキーボードのタイピング(20ポイント)

まず、技術的な概要

  1. 文字列strを変更;文字列str []がある不具合をセグメンテーション文字の配列を使用して、問題が解決されます。C ++文字列の後半で使用するようにしてください
  2. 入力(CIN、STR)のgetlineに、間違った答えにつながる、入力スペースである可能性があるため、>>エラーに対する答えをCINを使用して、問題が解決しました。
    詳細参照:https://www.cnblogs.com/tsruixi/p/11781506.html

二つ、C ++リファレンスコード

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn = 10010;
bool hashTable[256];
int main(){
    memset(hashTable,true,sizeof(hashTable));
    string str;
    getline(cin,str);
    int len = str.length();
    for(int i = 0; i < len; i++){
        if(str[i] >= 'A' && str[i] <= 'Z'){
            str[i] = str[i] - 'A' + 'a';
        }
        hashTable[str[i]] = false;
    }
    cin >> str;
    len = str.length();
    int flag = 0;
    for(int i = 0; i < len; i++){
        if(str[i] >= 'A' && str[i] <= 'Z'){
            int low = str[i] - 'A' + 'a';
            if(hashTable[low] == true && hashTable['+'] == true){
                cout << str[i];
                flag = 1;
            }
        }else if(hashTable[str[i]] == true){
            cout << str[i];
            flag = 1;
        }
    }
    if(flag == 0) cout << endl;
    return 0;
} 

おすすめ

転載: www.cnblogs.com/tsruixi/p/11785213.html