NC223709. SoftPasswords
描述
输入描述
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])