SDUT OJ 數據結構實驗之棧:行編輯器

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int lenstr,i,top;
	char str[255],a[255];
	while(gets(str)!=NULL)
	{
        lenstr=strlen(str);
        top=0;
		for(i=0;i<=lenstr-1;i++)
		{
			if(str[i]!='#'&&str[i]!='@')
			{
				a[top++]=str[i];
			}
			if(str[i]=='@')
			{
				top=0;
			}
			if(str[i]=='#')
			{
				if(top!=0)
					top--;
			}
		}
		for(i=0;i<top;i++)
		cout<<a[i];
		printf("\n");
	}
	return 0;
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章