zoukankan      html  css  js  c++  java
  • poj3650

    简单字符串处理,从规定位置pos开始查找,string::find(char *, pos);还要注意replace的用法string::replace(pos, length, char*);

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    
    string replacement[7][2] =
    {
    { "%", "%25" },
    { " ", "%20" },
    { "!", "%21" },
    { "$", "%24" },
    { "(", "%28" },
    { ")", "%29" },
    { "*", "%2a" } };
    
    int main()
    {
    	//freopen("D:\\t.txt", "r", stdin);
    	string st;
    	while (getline(cin, st) && st != "#")
    	{
    		for (int i = 0; i < 7; i++)
    		{
    			int pos = st.find(replacement[i][0]);
    			while (pos != string::npos)
    			{
    				st.replace(pos, 1, replacement[i][1]);
    				pos += 2;
    				pos = st.find(replacement[i][0], pos);
    			}
    		}
    		cout << st << endl;
    	}
    	return 0;
    }
  • 相关阅读:
    结构体的malloc与数组空间
    绘制K线图
    加载文件
    数据分析(绘图)
    GIT操作
    疑难杂症汇总
    Shell编程2
    shell编程1
    shell命令2
    Shell命令1
  • 原文地址:https://www.cnblogs.com/rainydays/p/1948653.html
Copyright © 2011-2022 走看看