m0_73394375 2022-09-16 21:25 采纳率: 100%
浏览 66
已结题

python和C语言的互转

Python转C语言

para = "Letting go of a negative habit happens by making one positive choice at a time. " \
       "Creating a desired achievement comes about in the same way."

para = para.split()
arr = []
num_a = 0
word_num = 0
word_line = 0
count_line = 0
max_line = 72

for p in para:
    if p == 'a':
        p = "//"+p+"//"
        num_a += 1
    word_num += 1
    word_line = len(p)
    count_line += word_line
    arr.append(p)

arr = ' '.join(arr)
print(arr)

输出是

Letting go of //a// negative habit happens by making one positive choice at //a// time. Creating //a// desired achievement comes about in the same way.

  • 写回答

3条回答 默认 最新

  • fuill 2022-09-16 23:21
    关注

    判断句子中的a即可

    img

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        char t[]={"Letting go of a negative habit happens by making one positive choice at a time. " 
           "Creating a desired achievement comes about in the same way."};
        int len=strlen(t);
        for(int i=0;i<len;i++)
        {
            if(t[i]=='a'&&i-1>0&&i+1<len-1)
            {
                if(t[i-1]==' '&&t[i+1]==' ')
                {
                    printf("//%c//",t[i]);
                }
                else
                {
                    printf("%c",t[i]);
                }
            }
            else
            {
                printf("%c",t[i]);
            }
        }
        printf("\n");
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月25日
  • 已采纳回答 9月17日
  • 创建了问题 9月16日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效