夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

SRM160〜163 Div.2 Easy

今日は昆布で解きまくってきました。

めんどくさいので問題名とコードだけ。

Substitute

class Substitute {
   public:
   int getValue(string key, string code)
  {
  	string num = "";
  	string tmp;
	for (int i=0; i<code.length(); i++) {
		for (int j=0; j<key.length(); j++) {
			if (key[j] == code[i]) {
				stringstream ss;
				j++;
				if (j == 10) j = 0;
				ss << j;
				if (num == "" || num == "0") {
					ss >> num;
				} else {
					ss >> tmp;
					num += tmp;
				}
				break;
			}
		}
	}
	stringstream ss;
	ss << num;
	int res;
	ss >> res;
	return res;
  }
};

CardCount

class CardCount {
   public:
   vector <string> dealHands(int numPlayers, string deck)
  {
  	vector <string> deal(numPlayers, "");
  	int apper = (int)(deck.length()/numPlayers);
  	if (deck.length() >= numPlayers) {
		for (int i=0; i<deck.length(); i++) {
			if (i+1 > apper*numPlayers) break;
			deal[i%numPlayers] += deck[i];
		}
	}
	return deal;
  }
};

LCMRange

class LCMRange {
   public:
int calc_gcj(int a, int b) {
	int A=0, B=0;
	if (a == max(a,b)) {
		A = a;
		B = b;
	} else {
		A = b;
		B = a;
	}
	if (A == B) return A;
	else return calc_gcj(B,A-B);
	return -1;
}
   int lcm(int first, int last)
  {
	vector <int> num;
	for (int i=first; i<=last; i++) {
		num.push_back(i);
	}
	for (int i=0; i<num.size(); i++) {
		for (int j=num.size()-1; j>i; j--) {
			// if (num[j]%num[i] == 0) num[j] /= num[i];
			int g = calc_gcj(num[i], num[j]);
			if (g != -1) num[j] /= g;
		}
	}
	int res = 1;
	for (int i=0; i<num.size(); i++) res *= num[i];
	return res;
  }
};

Inchworm

class Inchworm {
   public:
   int lunchtime(int branch, int rest, int leaf)
  {
	vector <int> leaves;
	int res = 0;
	for (int i=0; i<=branch; i+=leaf) {
		leaves.push_back(i);
	}
	for (int j=0; j<leaves.size(); j++) {
		if (leaves[j]%rest==0) {
			res++;
		}
	}
	return res;
  }
};

今はどんなゲームをつくるか・・・そこにつきます。

広告を非表示にする