淘先锋技术网

首页 1 2 3 4 5 6 7

信的内容由a-z的26个小写字母构成,而每个字母的宽度均会事先约定。例如字符宽度约定为[1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],那么就代表'a'到'd'四个字母的宽度分别是1,2,3,4,而'e'到'z'的宽度均为5

那么按照上述规则将给定内容S书写成一封信后,这封信共有几行?最后一行宽度是多少?

#include "iostream"
#include "vector"
#include "algorithm"
  
using namespace std;
int main()
{
    vector<int> vec(26,0);
    int i = 0;
    while(i < vec.size())
    {
        cin >> vec[i];
        if(vec[i] > 10 || vec[i] < 1)
            i--;
        i++;
    }
    int count = 1;//记录行数
    int num = 0;//记录最后一行个数
    string str;
    cin >> str;
    while(str.size() > 1000 || str.size() < 1)
        cin >> str;
    for(i = 0; i < str.size(); i++)
    {
        int index = str[i] - 'a';
        if(num + vec[index]> 100)
        {
            count++;
            num = vec[index];
        }
        else
            num += vec[index];
    }
    cout << count << " " << num << endl;
    return 0;
}