输入:
1 1 3
输出:
6
输入:
0 0 0
输出:
3
#include<unordered_map>
int main()
{
unordered_map<int,int>myvec;
int temp = 0;
int total = 0;
int arr[3] = { 0,0,0 };
for (int i = 0; i<3; ++i)
{
cin>>arr[i];
temp = arr[i] + 1;
myvec[temp] ++;
}
auto it = myvec.begin();
for (it; it != myvec.end(); ++it)
{
if(it->second != 0)
total += ((it->second / it->first)*it->first + (it->second % it->first)*(it->first));
}
printf("%d\n", total);
return 0;
}
题目2:
int main()
{
int myvec[26];
for (int i = 0; i<26; ++i)
{
cin>>myvec[i];
}
string str;
cin >> str;
int len = 0;
int count = 1;
int b = 0;
int j = 0;
while (j<str.length())
{
b = str[j] - 'a' ;
if (len + myvec[b] > 100)
{
count += 1;
len = 0;
}
else
{
len = len + myvec[b];
++j;
}
}
printf("%d %d\n", count, len);
return 0;
}