implementation strings *800

Please click on ads to support us..

Python Code:

for i in range(int(input())):
    flag=0
    s=input()
    c=input()
    for i in range(len(s)):
        if s[i]==c and (i+1)%2!=0:
            flag=1 
    if flag==1:
        print("YES")
    else:
        print("NO")

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define improve ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
#define ll long long 
#define el '\n'
using namespace std;
bool cmp(pair < ll, ll > x, pair<ll, ll>y)
{
    return x.second > y.second; 
}
vector<int> pre(vector<int>arr)
{
    vector<int>prefix(arr.size() + 1, 0); 
    for (int i = 1; i < prefix.size(); i++)
    {
        prefix[i] = prefix[i - 1]+ arr[i-1];
    }
    return prefix; 
}
vector<int> suf(vector<int>arr)
{
    vector <int>suffix(arr.size() + 1, 0);
    for (int i = arr.size() - 1; i >= 0; i--)
    {
        suffix[i] = suffix[i + 1] + arr[i];
    }
    return suffix; 
}
int max_mod(int x, int y) {
	return y ? max_mod(y, x % y) : x;
}
int main()
{
	improve;
    ll n; cin >> n; 
    while (n--)
    {
        string name; cin >> name;
        char temp; cin >> temp;
        bool flag = false; 
        for (int i = 0; i < name.size(); i++)
        {
            if (temp == name[i] && (i % 2 == 0))
            {
                flag = true; 
                break; 
            }
        }
        if (flag)
            cout << "YES" << el;
        else
            cout << "NO" << el; 
    }
    
    return 0; 
} 


Comments

Submit
0 Comments
More Questions

236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD