堆栈选择性翻转字符串:String:Reverse a string using Stack:the pointer is a very good tool actually
2009-11-29 04:29
609 查看
// TestString.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "string"
#include "stack"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *LongS="you are My love";
char *Find="My";
stack<char> MyStack;
char *phead=LongS;
char *rear=phead;
char *p=Find;
while(*phead!='/0')
{
while(*phead==*p)
{
phead++;
p++;
}
if(*p=='/0')
{
for(char *temp=phead-1;temp>=rear;temp--)
MyStack.push(*temp);
rear=phead;
p=Find;
}
else
{
MyStack.push(*rear++);
phead=rear;
p=Find;
}
}
while(!MyStack.empty())
{
cout<<MyStack.top();
MyStack.pop();
}
cin.get();
return 0;
}
//
#include "stdafx.h"
#include "iostream"
#include "string"
#include "stack"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *LongS="you are My love";
char *Find="My";
stack<char> MyStack;
char *phead=LongS;
char *rear=phead;
char *p=Find;
while(*phead!='/0')
{
while(*phead==*p)
{
phead++;
p++;
}
if(*p=='/0')
{
for(char *temp=phead-1;temp>=rear;temp--)
MyStack.push(*temp);
rear=phead;
p=Find;
}
else
{
MyStack.push(*rear++);
phead=rear;
p=Find;
}
}
while(!MyStack.empty())
{
cout<<MyStack.top();
MyStack.pop();
}
cin.get();
return 0;
}
相关文章推荐
- HDU 2037 circumgyrate the string(字符串翻转)
- IAR MSP430设置合理堆栈大小(the stack pointer for stack is outside the stack range)
- 指定字符串与主题所要求的形式不符The specified string is not in the form required for a subject
- Diesel watches australia is the very best dive wri
- If the only tool you have is Java, everything looks like a class
- Objective-C中 ==、isEqual、isEqualToString判断字符串相等
- 【LintCode】Reverse Words in a String 翻转字符串
- Spring tool suite编译不通过:Access restriction: The type XXX is not accessible
- ORA-23421: job number string is not a job in the job queue
- 使用Json-lib转换json字符串出现There is a cycle in the hierarchy!时的解决方案
- vmware-tool 安装缺少头文件 What is the location of the directory of C header files that match your running
- 安装vmware-tool出现the path""is not a valid path to the 3.4.6-2.10-desktop kernel headers
- Reverse Words in a String III 翻转字符串中的单词之三
- Is the Improvement of String.substring() in Java7 Really Reasonable?
- New work.New life. New begining.God is good.All the time.
- weblogic部署异常—org.xml.sax.SAXParseException: The string "--" is not permitted within comments
- Educational Codeforces Round 9 C. The Smallest String Concatenation(字符串排序)
- 【c语言】实现翻转字符串函数reverse_string
- The method isEmpty() is undefined for the type String/String
- The method list(String, Object[]) is ambiguous for the type BaseHibernateDao<M,PK>错误解决方法