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; 
    }
    
  • 相关阅读:
    数的划分终极版--背包法解决各类数的划分
    128.最长公共子序列
    整数划分类型题目--专练
    主函数
    LED类代码
    APM2.8地面站下载地址
    多文件函数调用
    流水灯
    APM的3DR无线数传的安装和调试
    闪烁的LED灯
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2614522.html
Copyright © 2011-2022 走看看