第一题:
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
long long sum = 0;
vector<long long> v(n, 0);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
long long minvalue = v[0];
for (int i = 0; i < v.size(); i++)
{
if (v[i] < minvalue)
{
minvalue = v[i];
}
}
for (int i = 0; i < v.size(); i++)
{
sum = sum + v[i] - minvalue;
}
cout << sum;
return 0;
}
第二题
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
int main()
{
string s;
getline(cin, s);
int n;
int a, b;
cin >> n;
vector<int> v;
for (int i = 0; i < 10; i++)
v.push_back(i);
while (n)
{
cin >> a >> b;
for (int i = 0; i < 10; i++)
{
if (v[i] == a)
v[i] = b;
}
n--;
}
for (int i = 0; i < s.length(); i++)
{
if (v[s[i] - '0'] != s[i] - '0')
s[i]= v[s[i] - '0']+'0';
}
cout << s;
return 0;
}
全部评论
(15) 回帖