ABCD * D = DCBA (Puzzle+Solution)

April 7, 2017 § Leave a comment

The Puzzle

“ABCD * D = DCBA”, Replace every character with a number to make the equation mathematically right.

The Solution using brute-force algorithm

#include<bits/stdc++.h>
using namespace std;
int main(){
    for(int a=0;a<=9;a++){
        for(int b=0;b<=9;b++)if(a!=b){
            for(int c=0;c<=9;c++)if(a!=c && b!=c){
                for(int d=0;d<=9;d++)if(a!=d && b!=d && c!=d){
                        if((a*1000+b*100+c*10+d)*d == (d*1000+c*100+b*10+a))
                            return cout<<"abcd\n"<<a<<b<<c<<d,0;
                }
            }
        }
    }

    return 0;
}

The final answer is 1089.

Advertisements

The 6th number is both square and triangular [Puzzle]

March 28, 2017 § Leave a comment

 

Solution – 330A – Cakeminator – codeforces

April 8, 2016 § Leave a comment

//c++
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r,c;
    cin>>r>>c;
    char arr[11][11];
    for(int i=0 ; i<r ; i++)
    {
        for(int j=0 ; j<c ; j++)         {             cin>>arr[i][j];
        }
    }
    int co=0; //how many dots
    int res1=0; //1stpart
    int re=0; //how many repeat
    for(int i=0 ; i<r ; i++)
    {
        co=0;
        bool repeat=false; //repeat or not
        for(int j=0 ; j<c ; j++)
        {
            if(arr[i][j]=='.')
                {co++;}
        }

        if(co==c && repeat==true)
            {res1=co-1+res1; repeat=true; re++;}
        else if(co==c)
            {res1=co+res1; repeat=true; re++;}
    }
    int res=0; //2ndpart
    for(int i=0 ; i<c ; i++)
    {
        co=0;
        bool repeat=false; //repeat or not
        for(int j=0 ; j<r ; j++)
        {
            if(arr[j][i]=='.')
                co++;
        }
        if(co==r)
            {res=co-re+res; repeat=true;}
    }
    cout<<res+res1;
}

Find more from my submissions HERE

Solution – 31A – Worms Evolution – codeforces

April 3, 2016 § Leave a comment

//c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[1001],x,y;
    cin>>n;
    for(int i=0 ; i<n ; i++)
        cin>>arr[i];
    for(int i=0 ; i<n ; i++)
    {
        for(int j=i+1 ; j<n ;j++)
        {
            x=arr[i]+arr[j];
            y=abs(arr[i]+arr[j]);
            for(int z=0 ; z<n ; z++)
            {
                if(x==arr[z])
                {cout<<z+1<<" "<<j+1<<" "<<i+1; return 0;}
                if(y==arr[z])
                {cout<<z+1<<" "<<j+1<<" "<<i+1; return 0;}
            }

        }
    }
    cout<<"-1"<<endl;
    return 0;

}

Find more from my submissions HERE

Solution – 49A – Sleuth – codeforces

April 3, 2016 § Leave a comment

//c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    bool res=false;
    int x=s.length()-1;
    while(res!=true)
    {
        res=isalpha(s[x]);
        if(res==true &&(s[x]=='A' ||s[x]=='a' || s[x]=='e' || s[x]=='E' || s[x]=='I' ||s[x]=='i' ||s[x]=='o' || s[x]=='O' || s[x]=='U' ||s[x]=='u' ||s[x]=='Y' || s[x]=='y'))
         {cout<<"YES"<<endl; return 0;}
        else if(res==true)
            {cout<<"NO"<<endl; return 0;}
        else
            x--;
    }

}

Find more from my submissions HERE

Solution – 443A – Anton and Letters – codeforces

April 3, 2016 § Leave a comment

//c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    set<char> a;
        for(int i=0 ; i<s.length() ; i++)
        {
            if(s[i]>=97 && s[i]<=122)
            {
                a.insert(s[i]);
            }

        }
        cout<<a.size()<<endl;

    return 0;
}

Find more from my submissions HERE

Solution – 656A – Da Vinci Powers – codeforces

April 3, 2016 § Leave a comment

//c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned short int a;
    cin>>a;
    long long arr[36]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968 };
    cout<<arr[a];
    return 0;
}

Find more from my submissions HERE

Where Am I?

You are currently browsing the c++ category at Orange Notes.

%d bloggers like this: