字符串结尾判断 | HJ99 自守数
#最优解 while True: try: n = int(input()) num =0 for i in range(n): b = str(i**2) if b.endswith(str(i)): num+=1 print(num) except: break # 我的代码 while True: try: n = int(input()) cnt = 0 for i in range(n+1): i_len = len(str(i)) if str(i**2)[i_len*(-1):] == str(i): cnt += 1 print(cnt) except: break
华为笔试刷题 文章被收录于专栏
高质量题: 1~40:HJ16,HJ22,HJ24,HJ26,HJ27,HJ28,HJ35,HJ37,HJ39; 40~80:HJ41,HJ42,HJ43,HJ44,HJ48,HJ50,HJ52,HJ53,HJ57,HJ61,HJ63,HJ64,HJ70,HJ71,HJ74,HJ77; 80~108:HJ82,HJ85,HJ88,HJ89,HJ93,HJ95,HJ98,HJ103,HJ107