列表

详情


NC223709. SoftPasswords

描述

Your favourite social media website is changing their policy on login password validation: a slight error when logging in is now acceptable! In particular, assuming the password you chose when creating the account is S, a password P entered while logging in will be accepted if any of the following conditions are met:
  • P and S are identical;
  • S can be formed from P by prepending a single digit (0–9); 
  • S can be formed from P by appending a single digit; 
  • S is equal to P after reversing the case of all letters in P.
To reverse the case of a string, replace all uppercase letters with their equivalent lowercase letters, and all lowercase letters with their equivalent uppercase letters, while leaving all other characters the same. For example, the case-reversal of pa55WORD is PA55word.

Any other attempted password P will be rejected. So for example, if S is c0deninja5, then c0deninja will be accepted, but not C0deninja5 or c0deninja51.

Write a program which, given alphanumeric strings S and P, determines whether P should be accepted. 

输入描述

The first line of the input is the string S, the stored password, and the second line of input is the password P that a user has entered while attempting to log in. Each string consists of only digits 0–9, lowercase letters a–z, and uppercase letters A–Z. The strings won’t contain spaces or any other extraneous characters, and will each contain at least one and at most 101 characters.

输出描述

Print Yes if P should be accepted according to the above rules, and No otherwise.

示例1

输入:

123
123a

输出:

No

示例2

输入:

abc
ABC

输出:

Yes

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Pascal 解法, 执行用时: 3ms, 内存消耗: 384K, 提交时间: 2021-08-19 12:20:21

var s,p:string;

function pd:boolean;
var i:longint;
    w:string;
begin
w:=p;
for i:=1 to length(s) do
    if (p[i] in ['A'..'Z']) then w[i]:=chr(ord(p[i])+32)
        else if p[i] in ['a'..'z'] then w[i]:=chr(ord(p[i])-32);
if w=s then pd:=true else pd:=false;
end;

begin
readln(s);
readln(p);
if (p=s) or (copy(s,2,length(s)-1)=p) and (s[1] in ['0'..'9']) or (copy(s,1,length(s)-1)=p) and (s[length(s)] in ['0'..'9']) or (pd)
    then write('Yes') else write('No');
end.

C++ 解法, 执行用时: 3ms, 内存消耗: 492K, 提交时间: 2021-08-25 22:39:48

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s,p,tmp;
	cin>>s>>p;
	if(s==p){puts("Yes");return 0;}
	for(int i=0;i<=9;i++){
		tmp=p+to_string(i);//整型转字符串 
		if(tmp==s){puts("Yes");return 0;}
		tmp=to_string(i)+p;
		if(tmp==s){puts("Yes");return 0;}
	}
	for(int i=0;i<p.length();i++)
	if(isalpha(p[i]))p[i]^=' ';//大小写转换 
	cout<<(s==p?"Yes":"No");
	return 0;
}

Python3 解法, 执行用时: 45ms, 内存消耗: 4640K, 提交时间: 2022-02-24 14:42:56

a=input()
s=input()
l_s=len(s)
l_a=len(a)
flag=1
if l_s==l_a:
    if s==a:
        flag=0
        # print(1)
    elif s==a.swapcase():
        flag=0
        # print(2)
else:
    if s==a[1:] and ord(a[0])>47 and ord(a[0])<58:
        flag=0
        # print(3)
    elif s==a[:-1] and ord(a[-1])>47 and ord(a[-1])<58:
        flag=0
        # print(4)
print('YNeos'[flag::2])

上一题