zoukankan      html  css  js  c++  java
  • POJ 3981(字符串替换)

    字符串替换
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 7290   Accepted: 3451

    Description

    编写一个C程序实现将字符串中的所有"you"替换成"we"

    Input

    输入包含多行数据

    每行数据是一个字符串,长度不超过1000
    数据以EOF结束

    Output

    对于输入的每一行,输出替换后的字符串

    Sample Input

    you are what you do

    Sample Output

    we are what we do
    
    第一:
    #include<stdio.h> 
    char str[1002]; 
    int main() 
    { 
      int i; 
      while(gets(str)!=NULL) 
      { 
        i=0;
       // while(str[i]!='\0')
       for(i=0;str[i]!='\0';i++) 
        if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') 
        { 
          printf("we"); 
          i+=2; 
        } 
        else
         {   
            printf("%c",str[i]); 
            //i++; 
         } 
         printf("\0");
        printf("\n");
      } 
      return 0; 
    }
    第二: 
    #include<stdio.h> 
    #include<string.h>
    char str[1002]; 
    int main() 
    { 
      int i; 
      while(gets(str)!=NULL) 
      { 
        i=0;
        while(str[i]!='\0') 
        if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') //短路,可以写道str[i+2] 
        { 
          printf("we"); 
          i+=3; 
          //printf("%d\n",i);
        } 
        else
        {   
            printf("%c",str[i]); 
            i++; 
        }
        printf("\0"); //必须是双引号 
        printf("\n");
      } 
      return 0; 
    }
    
  • 相关阅读:
    git命令回退代码并同步到远程仓库
    git拉取远程指定分支
    vue动态绑定样式
    友链
    css三大特性
    CSS的背景background
    元素显示模式(块元素、行内元素、行内块元素)
    CSS复合选择器
    快速生成HTML结构+CSS样式语法
    文本属性
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2614522.html
Copyright © 2011-2022 走看看