読者です 読者をやめる 読者になる 読者になる

一日一プロ

水たまり

using System;
using System.Collections.Generic;

namespace Rainy
{
	class MainClass
	{
		public class Data_B
		{
			public int left_p = 0;
			public int area = 0;

			public Data_B(int p, int a){
				left_p = p;
				area = a;
			}
		}

		public static List<int> stackA = new List<int> (); /* 総和 */
		public static List<Data_B> stackB = new List<Data_B> (); /* 各値 */
		const int ERROR= 0xFFFF;
		public static Data_B ERROR_B = new Data_B (0xFFFF, 0xFFFF);

		public static void Main (string[] args)
		{
			//Val
			int sum = 0;
			//Input
			string input = Console.ReadLine ();
			for(int i=0; i < input.Length; i++){
				switch (input [i]) {
				case '/':
					int t = a_pop ();
					if (t != ERROR) {
						/* 総和 */
						sum += i - t;
						/* 各和 */
						int b_sum = i - t;
						Data_B b_data_tmp = new Data_B (0, 0);

						while ((stackB.Count > 0) && (b_data_tmp = b_pop()).left_p >= t) {
							b_sum += b_data_tmp.area;
						}
						if (b_data_tmp.left_p < t) {
							b_push (b_data_tmp);
						}

						Data_B tmp = new Data_B (t, b_sum);
						b_push (tmp);

					}
					break;
				case '\\':
					a_push (i);
					break;
				case '_':
					/* Fall Throw */
				default:
					break;
				}
			}

			Console.WriteLine ("SUM={0}", sum);
			Console.WriteLine ("Area_NUM={0}", stackB.Count);
			for (int i = 0; i < stackB.Count; i++) {
				Console.WriteLine ("Area_{0} {1}", i, stackB [i].area);
			}
		}

		public static void a_push(int num){
			stackA.Add (num);
		}

		public static void b_push(Data_B b){
			stackB.Add(b);
		}

		public static int a_pop(){
			int ret = 0;
			if (stackA.Count > 0) {
				ret = stackA [stackA.Count-1];
				stackA.RemoveAt (stackA.Count-1);
			} else {
				ret = ERROR;
			}
			return ret;
		}

		public static Data_B b_pop(){
			Data_B ret = new Data_B (0, 0);
			if (stackB.Count > 0) {
				ret = stackB [stackB.Count-1];
				stackB.RemoveAt (stackB.Count-1);
			} else {
				ret = ERROR_B;
			}
			return ret;
		}
	}
}
広告を非表示にする