夢追い人

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

SRM155 Div.2 Easy Quipu

今日はやっと運動会練ですた。

出席率は・・・



・・・28%www

ポカミスしなけりゃ余裕

ポカミスしたから言ってあげる。
しかも二箇所でwww

PROBLEM STATEMENT

The Incas used a sophisticated system of record keeping 
consisting of bundles of knotted cords.
Such a bundle of cords is called a quipu.  Each individual 
cord represents a single number.
Surprisingly, the Incas used a base-10 positional system, 
just like we do today.  Each digit of a number 
is represented by a cluster of adjacent knots, with spaces 
between neighboring clusters.  The digit is 
determined by the number of knots in the cluster.
For example, the number 243 would be represented by a cord 
with knots tied in the following pattern


     -XX-XXXX-XXX-

where each uppercase 'X' represents a knot and each '-' 
represents an unknotted segment of cord (all quotes for 
clarity only).


Unlike many ancient civilizations, the Incas were aware of 
the concept of zero, and used it in their quipus.
A zero is represented by a cluster containing no knots.
For example, the number 204003 would be represented by a 
cord with knots tied in the following pattern


     -XX--XXXX---XXX-
        ^^    ^^^
        ^^    ^^^
        ^^    two zeros between these three segments
        ^^
        one zero between these two segments

Notice how adjacent dashes signal the presence of a zero.


Your task is to translate a single quipu cord into an 
integer.  The cord will be given as a string knots
containing only the characters 'X' and '-'.  There will be 
a single '-' between each cluster 
of 'X's, as well as a leading '-' and a trailing '-'.  The 
first cluster will not be empty.


DEFINITION
Class:Quipu
Method:readKnots
Parameters:string
Returns:int
Method signature:int readKnots(string knots)


CONSTRAINTS
 -knots contains between 3 and 50 characters, inclusive.
 -knots contains only the characters 'X' and '-'.  Note 
that 'X' is uppercase.
 -The first and last characters of knots are '-'s.  The 
second character is 'X'.
 -knots does not contain 10 consecutive 'X's.
 -knots will represent a number between 1 and 1000000, 
inclusive.

で、解答で〜す。

寂しいので方針いうと、最初の-は考えずそのあとに前の記号と今の記号で判別するみたいな。

数字を直接いじるのは難しいんで一回string型で答え作って後でintに戻しました。

class Quipu {
   public:
   int readKnots(string knots)
  {
	char log = knots[0];
	int count = 0;
	string num = "";
	for (int i=1; i<knots.length(); i++) {
		if (log == '-') {
			//cout << '-' << endl;
			if (knots[i] == 'X') {
				count++;
				log = 'X';
			} else if (knots[i] == '-') {
				num += '0';
				log = '-';
			}
		} else if (log == 'X'){
			//cout << 'X' << endl;
			if (knots[i] == 'X') {
				count++;
				log = 'X';
			} else if (knots[i] == '-') {
				num += (count+48);
				count = 0;
				log = '-';
			}
		}
	}
	//cout << num << endl;
	istringstream is(num);
	int n; is >> n;
	return n;
  }
};

さぁラジオ聞くか(笑)