[ create a new paste ] login | about

Link: http://codepad.org/h5IaKlTa    [ raw code | output | fork ]

C++, pasted on Apr 7:
#include "stdafx.h"

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

public ref class Rinban{
private:
    initonly array<String^>^ message;
    initonly array<String^>^ pattern;

public:
    Rinban()
    {
        message = gcnew array<String^>{
            "午後6時20分~午後10時の間の約3時間",
            "午後3時20分~午後7時の間の約3時間",
            "午後12時20分~午後4時の間の約3時間",
            "午前9時20分~午後1時、午後4時50分~午後8時半の間の各約3時間ずつ",
            "午前6時20分~午前10時、午後1時50分~午後5時半の間の各約3時間ずつ"
        };

        pattern = gcnew array<String^>{
        "1,2,3,4,5",
        "2,3,4,5,1",
        "3,4,5,1,2",
        "4,5,1,2,3",
        "5,1,2,3,4"
        };
        
     }

    void Run() {
        
        DateTime dtBase(1,1,1);
        DateTime today(DateTime::Now);
        DateTime rbBase(2011,4,7);

        const int GROUP_MIN = 1;
        const int GROUP_MAX = 5;
        const int GROUP_COUNT = 5;
        const int CORRECT_VALUE = rbBase.Day % GROUP_COUNT;
        
        String^ line;
        DateTime inputDay;
        int group;

        while(true){
            Console::Write("日付 >");
            line = Console::ReadLine();
            if(DateTime::TryParse(line,inputDay)){
                break;
            }
            Console::WriteLine("DateTime ParseFailed.");
        }

        while(true){
            Console::Write("グループ >");
            line = Console::ReadLine();
            if(int::TryParse(line,group)){
                if( group<GROUP_MIN || GROUP_MAX<group){
                    Console::WriteLine("Group Range Failed.");
                    continue;
                }
                break;
            }
            Console::WriteLine("Group Parse Failed.");
        }

        Console::WriteLine("日付 {0}", inputDay.ToString("yyyy/M/d"));
        Console::WriteLine("グループ {0}", group);
        Console::WriteLine("日付  | 停電時間");
        Console::WriteLine("--------+-----------");

        for(DateTime dt = (inputDay>today)
                ? inputDay.AddDays( (double) -(inputDay.DayOfWeek - DayOfWeek::Sunday) )
                : today.AddDays( (double) -(today.DayOfWeek - DayOfWeek::Sunday) );
            dt < inputDay.AddMonths(3);
            dt = dt.AddDays(1))
        {
            Console::WriteLine("{0,2}月{1,2}日{2}|{3} {4}",
                dt.Month,
                dt.Day,
                (dt.DayOfWeek == DayOfWeek::Sunday) ? "S" : " ",
                pattern[ ( (dt - dtBase).Days + CORRECT_VALUE ) % GROUP_COUNT ],
                message[ ( (dt - dtBase).Days + CORRECT_VALUE - group ) % GROUP_COUNT ]
            );
        }
    }
};
int main(array<System::String ^> ^args)
{
    Rinban r;
    r.Run();
    Console::ReadKey();
    return 0;
}


Output:
1
2
3
Line 19: error: stdafx.h: No such file or directory
Line 4: error: 'System' is not a namespace-name
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: