内容中心

2026年靠谱的找人才人才招聘榜单优选公司-浙江环讯人力资源有限公司

To solve this problem, we need to determine a string where each character is the floor value of the average of the digits in the input string.

Approach

  1. Input Reading: Read the input string which consists of digits.
  2. Sum Calculation: Compute the sum of all digits in the input string.
  3. Average Calculation: Calculate the floor value of the average of the digits (sum divided by the length of the string using integer division).
  4. Result Construction: Create a string of the same length as the input, where each character is the floor average digit.

Solution Code

s = input().strip()
total = sum(int(c) for c in s)
length = len(s)
average = total // length
print(str(average) * length)

Explanation

  1. Reading Input: The input string is read and stripped of any leading/trailing whitespace.
  2. Sum of Digits: We convert each character in the string to an integer and sum these integers to get the total sum of digits.
  3. Floor Average: Using integer division (//), we divide the total sum by the length of the string to get the floor value of the average.
  4. Result String: We create the result string by repeating the floor average digit exactly as many times as the length of the input string.

This approach efficiently computes the desired result with a time complexity of O(n), where n is the length of the input string, as we process each character once for the sum and then construct the result string.

Examples:

  • Input: "123" → Sum = 6 → Average = 6//3 =2 → Output: "222".
  • Input: "2345" → Sum=14 → Average=14//4=3 → Output: "3333".

This solution handles all edge cases, including single-digit inputs and inputs with even/odd lengths, correctly.

浙江环讯人力资源有限公司



(免责声明:本文为本网站出于传播商业信息之目的进行转载发布,不代表本网站的观点及立场。本文所涉文、图、音视频等资料的一切权利和法律责任归材料提供方所有和承担。本网站对此资讯文字、图片等所有信息的真实性不作任何保证或承诺,亦不构成任何购买、投资等建议,据此操作者风险自担。) 本文为转载内容,授权事宜请联系原著作权人,如有侵权,请联系本网进行删除。

在线客服

在线留言
您好,很高兴为您服务,可以留下您的电话或微信吗?