爱奇艺2019秋招c++20180915笔试题
第一题://小的一组里;从小到大 依次增长;或者大的一组里;从大到小变 //样例:888999->888996#include <bits/stdc++.h>
using namespace std;
int main(){
string str;
while(cin>>str)
{
string str1 = str.substr(0, 3);
string str2 = str.substr(3);
int sum1, sum2,cnt1=0,cnt2=0,cnt=0;
sum1 = str[0] + str[1] + str[2];
sum2 = str[3] + str[4] + str[5];
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
//小的一组里;从小到大 依次增长;或者大的一组里;从大到小变
if (sum1 >= sum2)
{
int x = sum1 - sum2,xs=x;
int i = 0,j=2;
while (x>0)
{
if (str1[j] - '0' > '9' - str2[i])
{
x -= str1[j--] - '0';
cnt++;
}
else
{
x -= '9' - str2[i++];
cnt++;
}
}
}
else
{
int x = sum2 - sum1, xs = x;
int i = 0, j = 2;
while (x>0)
{
if (str2[j] - '0' > '9' - str1[i])
{
x -= str2[j--] - '0';
cnt++;
}
else
{
x -= '9' - str1[i++];
cnt++;
}
}
}
cout << cnt<< endl;
}
return 0;
}
第二题;
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,p,cnt=1;
while(cin>>n>>m>>p)
{
vector<int> food;
while (n--)
{
int ai;
cin >> ai;
food.push_back(ai);
}
while (m--)
{
char op; int x;
cin >> op >> x;
if (op == 'A')
food[x - 1]++;
else if (op == 'B')
food[x - 1]--;
}
int temp = food[p-1];
sort(food.begin(), food.end());
reverse(food.begin(), food.end());
for (int i : food)
{
if (i != temp)
cnt++;
else break;
}
cout << cnt << endl;
}
return 0;
}
#爱奇艺##秋招#using namespace std;
int main(){
int n,m,p,cnt=1;
while(cin>>n>>m>>p)
{
vector<int> food;
while (n--)
{
int ai;
cin >> ai;
food.push_back(ai);
}
while (m--)
{
char op; int x;
cin >> op >> x;
if (op == 'A')
food[x - 1]++;
else if (op == 'B')
food[x - 1]--;
}
int temp = food[p-1];
sort(food.begin(), food.end());
reverse(food.begin(), food.end());
for (int i : food)
{
if (i != temp)
cnt++;
else break;
}
cout << cnt << endl;
}
return 0;
}