1032 挖掘机技术哪家强 (20分)
只需要注意数组个数要取大,不然最后一个测试点出错。
#include<iostream>
#include<string>
#include<vector>
using namespace std;int main()
{int sum = 0;cin >> sum;int bian = 0, fen = 0,max=0,maxbian=0,maxfen=0;int arr[1000000] = { 0 };//这里一定要取大,不然最后一个测试点不通过for (int i = 0; i < sum; i++){cin >> bian >> fen;arr[bian] += fen;if (bian > max)//找出最大编号,减少计算次数max = bian;}for (int i = 1; i <= max; i++)//找出最大点{if (maxfen < arr[i]){maxbian = i;maxfen = arr[i];}}cout << maxbian << " " << maxfen;return 0;
}
1033 旧键盘打字 (20分)
需要用getline输入,因为题目要求是坏键盘可以为空,cin无法输入空,最后一个测试点就是过不去????
#include<iostream>
#include<string>
#include<vector>
using namespace std;int main()
{string a, b;getline(cin, a);getline(cin, b);int temp = 0;if (!a.size()){for (int i = 0; i < b.size(); i++)cout << b[i];return 0;}for (int i = 0; i < a.size(); i++){if (a[i] == '+'){for (int i = 0; i < b.size(); i++){if (b[i] >= 'A' && b[i] <= 'Z')b[i] = '*';if (b[i] == '+')b[i] = '*';}}else if (a[i] >= 'A' && a[i] <= 'Z'){char temp = a[i] - 'A' + 'a';for (int i1 = 0; i1 < b.size(); i1++){if(b[i1]==temp)b[i1] = '*';}}else{for (int i1 = 0; i1 < b.size(); i1++){if(b[i1]==a[i])b[i1] = '*';}}}for (int i = 0; i < b.length(); i++){if (b[i] != '*'){cout << b[i];temp = 1;}}if (temp == 0)//如果全都是无法输出就输出一个回车{cout << endl;}return 0;
}