题解 | 一封奇怪的信

一封奇怪的信

https://www.nowcoder.com/practice/d7764905e41a413c98900e22a9cc4ec3

//活动地址: 牛客春招刷题训练营 - 编程打卡活动
#include<bits/stdc++.h>

using  namespace std;

#define mod 1000000007

typedef long long ll;

#define int  long long

inline ll read() // void int &n

{

    ll s=0,f=1;

    char c=getchar();

    while(c>'9'||c<'0')     

{

        if(c=='-')  

            f=-1;   

        c=getchar();

    }

    while(c>='0'&&c<='9')

    {

        s=(s<<1)+(s<<3)+c-'0';

        c=getchar();

    }

    return s*f;

}

inline void write(int n)

{

if(n<0)

{

  putchar('-');

  n=-n;

}

    

if(n>10) write(n/10);

putchar(n%10+'0');

}

int jiechen(int n)

{

    int sum = 1;

    for (int i = 2; i <= n; i++)

        sum = sum * i % mod;

    return sum % mod;

}

int qsm(ll a, ll p)

{

    ll s=1;

    while(p)

    {

        if(p&1)

         s=s*a%mod;

      a=a*a%mod;

    }

       return s;

}

ll isprime(ll x)

{

    if(x<2)

        return 0;

    for(int i=2;i<=x/i;i++)

        if(x%i==0)

            return 0;

    return 1;
}

bool cmp(int x, int y){
    return x>y;
}

const int N=3e6+10;

const int M =100000;

int len[26];
void solve(){
    // 首先打表   记录好每个 字母对应的宽度   再一个一个遍历
   for(int i=0;i<26;i++)cin>>len[i];
   string s;
   cin>>s;
   int raw=1,ans=0;
   int sum=100;
   for(auto x:s){
      if(sum-len[x-'a']>=0)sum-=len[x-'a'];
      else {
        raw++;
        sum=100;
        sum-=len[x-'a'];
      }
   }
   // 最后输出答案
   cout<<raw<<" "<<100-sum;
}

signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
    int _=1;
    //cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务