资料结构_输入输出字元比对

题目

Input : 正整数,不可超过20位数Output : 将输入的数*2倍,判断2倍后的数里所有字元是否全为输入字元,同时输入的数里的所有字元也要全部存在于2倍数中,如果符合输出"Yes",反之输出"No"Output :输入的数的2倍值Example:
Input : 123456789
Output : Yes
Output : 246913578

第一版,(错一题测资)

[测资]输入中有数字不在结果里,但结果都在输入中假设输入12、输出2,若只跑Output(2)的迴圈可确定2在12里,但12却没都在2里,没完全符合
sInput = input()i_double = int(sInput) * 2for i in str(i_double):    if not i in sInput:        print('No')        print(i_double)        breakelse:    print('Yes')    print(i_double)

第二版

[解决]输入中有数字不在结果里,但结果都在输入中跑完Output()的迴圈后,再跑一次Input的迴圈
sInput = input()i_double = int(sInput) * 2for i in str(i_double):    if not i in sInput:        print('No')        print(i_double)        breakelse:    for j in sInput:        if not j in str(i_double):            print('No')            print(i_double)            break    else:        print('Yes')        print(i_double)'''[测资]输入中有数字不在结果里,但结果都在输入中输入12,输出2,若只跑完Output(2)的迴圈可确定2在12里,但12却没都在2里,没完全符合需print("No")python 有for else,若其他语言要加个boolean判断,否则会一直print('Yes')'''

本文纯自己做题目之笔记,如有更好的方法再麻烦各位指教~~


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章