games greedy strings *800

Please click on ads to support us..

Python Code:

for it in range(int(input())):
    s=input()
    a=[ord(i)-ord('a')+1 for i in s]
    if len(a)==1:
        print('Bob',a[0])
    elif len(a)%2:
        print('Alice',sum(a)-2*min(a[0],a[-1]))
    else:
        print('Alice',sum(a))

C++ Code:

#include<bits/stdc++.h>
// #include<pthread.h>
using namespace std;
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}
// #define int long long
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define vc vector<char>
#define L cout<<'\n';
#define R return;
#define E cerr<<'\n';
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (ll i=a; i<b; ++i)
#define rev(i,a,b) for (ll i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define seea(a,x,y) for(ll i=x;i<y;i++){cin>>a[i];}
#define seev(v,n) for(ll i=0;i<n;i++){ll x; cin>>x; v.push_back(x);}
#define sees(s,n) for(ll i=0;i<n;i++){ll x; cin>>x; s.insert(x);}
// const ll inf = INT_MAX;
// const ld ep = 0.0000001;
// const ld pi = acos(-1.0);
const ll mod = 998244353;
// const ll N = 1e5 + 2;
// const int N = 10010;
// const int N1 = 5010;
// const ll mod = 998244353;
// ll dp[1010][100010];
// int dp[5002][5002];
// int a[5002];
// int dp2[5002];
// ll imp[N];
// ll size[N];
// vector<ll> v[1010][1010];
// int n, m;
// int a[1010][1010];
// bool vis[1000010];
// vector<vector<int>> v(1000010);
void solve();
// vector<bool> isPrime;

// void is()
// {
//     isPrime.assign(21,true);
//     isPrime[0]=isPrime[1]=false;
//     for(ll i = 2; i*i <= 21; i++)
//     {
//         if(isPrime[i])
//         {
//             for(ll j=i*i; j<=21; j+=i)
//                 isPrime[j]=false;
//         }
//     }
// }

int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("inputt.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    IOS
    ll test=1;
    // is();
    see(test);
    while(test--)
    {
        solve();
    }
} 

// void dfs(int i,int j,int &p)
// {
//     if(a[i][j]==0) return;
//     if(i>=n || j>=m || i<0 || j<0) return;
//     if(vis[i][j]==true) return;
//     // putl(i,j);
//     p = p + a[i][j];
//     vis[i][j]=true;
//     dfs(i+1,j,p);
//     dfs(i,j+1,p);
//     dfs(i-1,j,p);
//     dfs(i,j-1,p);
// }

void solve()
{
    string s;
    see(s);
    ll ans = 0;
    rep(i,0,s.length())
        ans+=s[i]-'a'+1;
    if(s.length()%2==0)
    {
        putl("Alice", ans);
    }
    else if(s.length()==1)
    {
        putl("Bob",ans);
    }
    else if(s.length()%2==1)
    {
        if(s[0]>s[s.length()-1])
        {
            ans = ans - 2*(s[s.length()-1]-'a'+1);
            if(ans>0)
                putl("Alice",ans);
            else
                putl("Bob",ans);
        }
        if(s[0]<=s[s.length()-1])
        {
            ans = ans - 2*(s[0]-'a'+1);
            if(ans>0)
                putl("Alice",ans);
            else
                putl("Bob",ans);
        }
    }
}



Comments

Submit
0 Comments
More Questions

1405A - Permutation Forgery
1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess
467B - Fedor and New Game
252C - Points on Line
735C - Tennis Championship
992A - Nastya and an Array
554A - Kyoya and Photobooks
79B - Colorful Field
265B - Roadside Trees (Simplified Edition)
1362C - Johnny and Another Rating Drop
1214C - Bad Sequence
1091B - New Year and the Treasure Geolocation
244A - Dividing Orange
1061C - Multiplicity
1312A - Two Regular Polygons
801A - Vicious Keyboard
510B - Fox And Two Dots
616D - Longest k-Good Segment
1604A - Era
555B - Case of Fugitive
551A - GukiZ and Contest
1399F - Yet Another Segments Subset
1371C - A Cookie for You
430B - Balls Game
1263A - Sweet Problem
1332B - Composite Coloring