2014期卒業生の華為機試験問題(厦大場)


タイトル:
タイトルの説明(60点):
キーボードで小文字(a~z)の文字列を入力します.文字列フィルタを作成してください.文字列に同じ文字が複数表示された場合、最初に表示されない文字をフィルタします.たとえば、文字列「abacacde」のフィルタリング結果は「abcde」です.要求実現関数:void stringFilter(const char*pInputStr,long lInputLen,char*pOutputStr);
【入力】pInputStr:入力文字列lInputLen:入力文字列長【出力】pOutputStr:出力文字列、空間はすでに開いて、入力文字列と同じ長さ;【注意】この関数機能アルゴリズムを完了するだけで、中にIOの入出力例入力を必要としない:「deefd」出力:「def」入力:「afafaf」出力:「af」入力:「pppppppppp」出力:「p」
C++実装コードは以下の通りである.
#include 
#include 
using namespace std;

#define  MAXLEN 100

void stringFilter(char *pInputStr, long lInputLen, char *pOutputStr)
{
	pOutputStr[0] = pInputStr[0];
	int k = 1;
	for(int i=1; i>pInputStr;
	long lInputLen = strlen(pInputStr);
	char pOutputStr[MAXLEN];
	stringFilter(pInputStr, lInputLen, pOutputStr);
	for(int i=0; i

タイトルの説明(40点):
キーボードで小文字(a~z)の文字列を入力します.文字列圧縮プログラムを作成し、文字列に連続して出席する重複文字を圧縮し、圧縮された文字列を出力してください.圧縮ルール:1.連続して繰り返される文字のみを圧縮します.例えば、文字列「abcbc」は、連続する重複文字がないため、圧縮された文字列は「abcbc」である.2.圧縮フィールドの形式は「文字の繰り返し回数+文字」です.例えば、文字列「xxxyyyyyyyyz」が圧縮されると「3 x 6 yz」要求実現関数となる:void stringZip(const char*pInputStr,long lInputLen,char*pOutputStr);【入力】pInputStr:入力文字列lInputLen:入力文字列長【出力】pOutputStr:出力文字列、空間はすでに開いて、入力文字列と同じ長さ;【注意】この関数機能アルゴリズムを完了するだけで、中間にIOの入出力例入力を必要としない:「cccddecc」出力:「3 c 2 de 2 c」入力:「adef」出力:「adef」入力:「pppppppppp」出力:「8 p」
C++コードは以下の通りです.
#include 
using namespace std;
#define MAXLEN 100

void int_to_str(int num, int &j_output, char *pOutputStr)
{
	int start = j_output;
	char tmp;
	while (num != 0)
	{
		pOutputStr[j_output++] = num%10 + '0';
		num = num/10;
	}
	int end = j_output-1;
	while (start < end)
	{
		tmp = pOutputStr[start];
		pOutputStr[start] = pOutputStr[end];
		pOutputStr[end] = tmp;
		start++;
		end--;
	}
}

void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr)
{
	char tmp_str = pInputStr[0];
	int j_output = 0;
	int num_str = 0;
	for(int i=0; i>pInputStr;
	stringZip(pInputStr,strlen(pInputStr),pOutputStr);
	cout<

タイトルの説明(50点):
キーボードで100以内の正の整数の加算・減算式を入力し、プログラム出力演算結果文字列を作成してください.文字列は、「オペランド1演算子オペランド2」、「オペランド」と「演算子」の間にスペースで区切られた形式で入力されます.補足説明:1.オペランドは正の整数であり,計算結果がオーバーフローする場合を考慮する必要はない.2.入力式フォーマットが間違っている場合、出力結果は「0」となります.要求実現関数:void arithmetic(const char*pInputStr,long lInputLen,char*pOutputStr);【入力】pInputStr:入力文字列lInputLen:入力文字列長【出力】pOutputStr:出力文字列、空間はすでに開いて、入力文字列と同じ長さ;【注意】この関数機能アルゴリズムを完成するだけで、中にはIOの入出力例入力が必要ありません:“4+7”出力:“11”入力:“4-7”出力:“-3”入力:“9++7”出力:“0”注:フォーマットエラー