ファーウェイ社2020回博士募集-搭乗試験(2019年9月25日)

3651 ワード

(1)2組の文字列を入力し、第1グループの文字列に第2グループの文字列を問い合わせる必要があり、存在する場合は文字列の中にあるので文字を*番で置き換える.
#include
#include
using namespace std;

int main()
{
	string str1, str2;
	while (cin >> str1 >> str2)
	{
		int t = str1.find(str2);
		if (t >= 0)
		{
			for (int i = 0; i < str2.length(); i++)
			{
				str1[t + i] = '*';
			}
		}
		cout << str1 << endl;
	}
	return 0;
}

(2)入力説明:入力には複数のテストデータが含まれる.各入力の最初の行は、2つの正の整数NおよびM(0次のように入力します.
6 8 1 2 3 4 5 6 Q 1 6 U 2 6 U 4 3 Q 2 4 Q 1 2 U 1 3 U 2 1 Q 1 3
 
出力:
3 6 4 5
#include 
#include 
#include 
using namespace std;
int main()
{
	int M, N;
	while (cin >> M >> N)
	{
		vector num, result;
		int begin = 0;
		int end = 0;
		char c;
		
		for (int i = 0; i < M; i++)
		{
			int tmp = 0;
			cin >> tmp;
			num.push_back(tmp);
		}

		for (int j = 0; j < N; j++)
		{			
			cin >> c;
			cin >> begin;
			cin >> end;

			if (c == 'Q')
			{
				int sum = 0;
				for (int j = begin - 1; j < end; j++)
				{
					sum += num[j];
				}
				int average = floor(sum / (end - begin + 1));
				result.push_back(average);
			}
			else if (c == 'U')
			{
				num[begin - 1] += end;
			}
		}

		for (int k = 0; k < result.size(); k++)
		{
			cout << result[k] << endl;
		}
	}
	return 0;
}

(3)訓練能力値の統計
前の日が現在の日よりミスが多い場合、現在の日のコンピテンシー値-1
前の日が現在の日よりミス回数が少ない場合、現在の日の能力値+1
前の日が現在の日よりミスの回数が多い場合、現在の日のコンピテンシー値は変更されません.
初期コンピテンシー値は0です.
 
説明の入力
T組のテストデータを表す一字数字Tを入力する
各テストデータのセットについて、1行目は1つの数nを入力し、小立訓練日数を表し、2行目はn個の数を入力し、a 1、a 2......anは小立の毎日のミス回数を表す
1<=n ,ai <= 100000
 
出力の説明
各トレーニングテストデータのセットについて、2つの数を出力して、小立能力値が最高いくらであるか、およびトレーニング終了後の小立最終能力値がいくらであるかを示します.
 
次のように入力します.
2 3 1 3 2 3 2 1 3
 
出力:
1 1
1 1
 
/* */
#include
#include
#include
#include
using namespace std;
int main()
{
	int round = 0;
	int  day;
	vector error, ability, result;
	while (cin >> round)
	{
		int roundtmp = round;
		while (roundtmp--)
		{
			cin >> day;
			int tmp;
			error.clear();
			ability.clear();
			for (int i = 0; i < day; i++)
			{
				cin >> tmp;
				error.push_back(tmp);
			}

			for (int j = 0; j < day; j++) // 
			{
				if (j == 0)
				{
					ability.push_back(0);
				}
				else
				{
					int tmpability = ability[j - 1];
					for (int m = 0; m < j; m++)
					{
						if (error[m] < error[j])
						{
							tmpability++;
						}
						else if (error[m] > error[j])
						{
							tmpability--;
						}
					}
					ability.push_back(tmpability);
				}
			}

			result.push_back(*max_element(ability.begin(), ability.end()));
			result.push_back(ability[day - 1]);

			//cout << *max_element(ability.begin(), ability.end()) << "	" << ability[day - 1] << endl;
		}

		for (int k = 0; k < round; k++)
		{
			cout << result[2*k] << " " << result[2*k+1] << endl;
		}
	}
	return 0;
}