字符串替换 java/c++

//java
import java.util.*;
import java.io.*;
public class replace
{  
  public static void main(String args[]) 
  { 
	  Scanner cin=new Scanner(System.in);

	  while(cin.hasNext())
	  {
		String str=cin.nextLine();
		if(str.charAt(0)=='0') break;
		str=str.replaceAll("you","we");  
		System.out.println(str);
	  }
	
      
  }

 
}  
#include<iostream>
#include<string>
using namespace std;
int main( )
{
    string str;
    int pos;
    while(getline(cin,str))
    {
      while((pos=str.find("you"))!=-1)
        str.replace(pos,3,"we");
        cout<<str<<endl;
    }
    return 0;
}
c++强大啊。0ms  ,java用了172ms

posted on 2011-05-10 19:39  more think, more gains  阅读(204)  评论(0编辑  收藏  举报

导航