Categories
不学无术

1050. String Subtraction (20)

1050. String Subtraction (20)
时间限制
10 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 – S2 for any given strings. However, it might not be that simple to do it fast.
Input Specification:
Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.
Output Specification:
For each test case, print S1 – S2 in one line.
Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.

===================================================
不用动啥脑子的一道题,只要避免使用cin/cout就行了。反正内存给了好大好大,要争取时间的话,就给一共128个ascii字符做个map,里面存放是不是被ban掉了。
===================================================

#include 
using namespace std;
static char S1[10000];  //S1
static char S2[10000];  //S2
static char S3[10000];  //result
static bool mapAscii[127];
int main()
{
	char* pS1 = &S1[0];
	char* pS2 = &S2[0];
	gets(pS1);
	gets(pS2);
	int asc;
	while( (*pS2) != '')
	{
		asc = (int)(*pS2);
		mapAscii[asc] = true;
		pS2++;
	}
	char* pS3 = &S3[0];
	while( (*pS1) != '')
	{
		asc = (int)(*pS1);
		if(!mapAscii[asc])
		{
			(*pS3) = (char) asc;
			pS3++;
		}
		pS1++;
	}
	(*pS3) = ''; // EOL
	puts(&S3[0]);
	//system("pause");
	return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.