Skip to main content

Posts

Showing posts from April, 2018

GCJ1C09A - All Your Base

Ref Link #include <iostream> #include <map> #include <string> #include <algorithm> using namespace std; map<char,int> memo; int main() {     int t, next;     string s;     cin >> t;     for(int k = 1; k <= t; k++)     {         cin >> s;         memo.clear();         // number does not start with 0 so min value for the first char is 1         memo[s[0]] = 1;         //next value to assign to a symbol         next = 0;         for(int i = 1; i < s.size(); i++)         {             if(memo.count(s[i]) == 0)             {                 memo[s[i]] = next++;                 // 1 is already used so increment next value once again                 if(next == 1)                 {                     next++;                 }             }         }         long long value = 0;         // base will be number of unique character in the string or the highest value assigned to any character         int

GAMES - HOW MANY GAMES

#include <iostream> #include <cmath> using namespace std; long gcd(long a, long b) {     if(b != 0)     {         long t = b;         b = a % b;         a = t;         return gcd(a, b);     }     return a; } int main() {     int t, n;     string s;     cin >> t;     cin.get();       long num;     long number;     int count;     bool flag;     while(t--)     {         cin >> s;         count = 0;         number = 0;         flag = false;         num = 1;         for(int i=s.size()-1; i>=0; i--)         {             if(s[i]=='.')             {                 flag=true;                 break;             }             else             {                 count++;             }         }         for(int i=0; i<s.size(); i++)         {             if(s[i]!='.')             {                 number=number*10 + (s[i]-48);             }         }         if(flag)         {             num