Editorial for Мутация


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерно решение на C++:

#include <iostream>
using namespace std;
int nod(int a, int b)
{
    while (b != a)
       if (a>b) 
          a=a-b;
       else 
          b=b-a;
    return a;
}
int main()
{
    int n;
    cin>>n;

    string s,s1;
    int br=0;
    for (int i=1; i<=n;i++)
    {
        cin>>s;
        s1=s;
        int a=0,b=0;

        for (int i=0;i<s.size();i++)
        { 
          if (s[i]%2==0)
          {
             if (s[i]=='0')
                 s[i]='9'; 
             else 
                 s[i]--;
          }
          else 
          {
             if (s[i]=='9')
                 s[i]='0';  
             else 
                 s[i]++;
          }

         a=a*10+s[i]-48;
         b=b*10+s1[i]-48;
       }

       if (nod(a,b)<10)
          br++;
    }

    cout<<br<<endl;

    return 0;
}

Comments

There are no comments at the moment.