Tuesday, July 8, 2014

TopCoder High School SRM 38 Level one - 250 pt - Josh String solution

TopCoder High School SRM 38 Level one - 250 pt - Josh String editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm38

TopCoder High School SRM 38 Level one - 250 pt - Josh String solution: 


#include <iostream>
#include <vector>
using namespace std;

class JoshString {
    public: string isJoshString(string s) {
        vector <string> v;
        int a=0, flag=0;
        v.push_back(s);
        for(int i=0; i<v[0].length(); i++) a+=v[0][i]-'a'+1;
        for(int i=2; i<a; i++) {
            if(a%i==0) {
                flag=1;
                break;
            }
        }
        if(flag==0) return "YES";
        else return "NO";
    }
};

No comments:

Post a Comment