PTA 1033 旧键盘打字 (20 分)

题目:
https://pintia.cn/problem-sets/994805260223102976/problems/994805288530460672

 

这题是真的骚,键盘缺少的按键还能是空字符串。。。

(强烈暗示第一行字符串可能是空的。。。。以后遇到这种文字游戏要多加注意)

 

既然可能是空串,那么用gets()函数可不可以呢? 理论上是可以的,但是PTA的编译器并编译通过(虽然好像是在stdio.h里面),所以迫不得已使用getline  

 

用法:

此时两个数据结构都变成了string类型:

需要添加头文件:

 

代码:

//1033
#include
#include
#include
#include
#include
using namespace std;
#define MAXN 100010

string Std,wrong;
char res[MAXN];
bool useful[300];

int main()
{
    int i;
    bool shift=true;
    int cnt;

    getline(cin,wrong);
    getline(cin,Std);
    memset(useful,true,sizeof(useful));
    for(i=0;i='A'&&wrong[i]<='Z'))
        {
            useful[wrong[i]]=false;
            useful[wrong[i]+32]=false;
        }
        else if(wrong[i]=='+')
        {
            shift=false;
            useful[wrong[i]]=false;
        }
        else
            useful[wrong[i]]=false;
    }
    for(i=0,cnt=0;i='A'&&Std[i]<='Z'&&(!shift)))
            continue;
        else
        {
            printf("%c",Std[i]);
            cnt++;
        }
    }
    if(cnt)
        printf("\n");
    return 0;
}

 

你可能感兴趣的:(PTA 1033 旧键盘打字 (20 分))