安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技

C语言实现字符串子串统计

  • 日期: 2027-11-30 06:40:07
  • 标签: 常规

#include <stdio.h>

int main() { char str[100001]; scanf('%s', str);

int count = 0;
int i = 0;
while (str[i] != '\0') {
    if (str[i] == '1') {
        count++;
    }
    i++;
}

int answer = count * (count + 1) / 2;
printf('%d\n', answer);

return 0;

}


原文地址: https://www.cveoy.top/t/topic/o19C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 三审双签字一抽查制度:加强监督,提高效率
  • 下一篇: 勇敢的海盗少女:李薇的海洋冒险

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2