1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
#ifndef __PROGTEST__
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#define EASTER_OK 0
#define EASTER_INVALID_FILENAME 1
#define EASTER_INVALID_YEARS 2
#define EASTER_IO_ERROR 3
#endif /* __PROGTEST__ */
const char *HEADER =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <html>\n"
"<head>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> <title>C++</title>\n"
"</head>\n"
"<body>\n"
"<table width=\"300\">\n"
"<tr><th width=\"99\">day</th><th width=\"99\">month</th><th width=\"99\">year</th></tr>\n";
const char *FOOTER =
"</table>\n"
"</body>\n"
"</html>\n";
int checkname(const char * outFileName)
{
if(strlen(outFileName)<=5)
return EASTER_INVALID_FILENAME;
string fn = outFileName;
if(fn.substr(fn.find_last_of(".") + 1) == "html")
{
return EASTER_OK;
} else
{
return EASTER_INVALID_FILENAME;
}
}
int checkyear(const char * years){
int yearsv=0;
yearsv = atoi(years);
if((yearsv > 1582) && (yearsv < 2200))
return EASTER_OK;
else return EASTER_INVALID_YEARS;
}
int easterReport ( const char * years, const char * outFileName )
{
if(checkname(outFileName) != EASTER_OK)
return EASTER_INVALID_FILENAME;
string rokys = years;
string rokyz = years;
char c;
char prvni[5];
char druhy[5];
int j = 4;
cout << rokys;
int interval = 0;
int intervalsingle = 0;
int vysinter = 0;
int rokypole[1000];
char rokpole[4];
int quantu = 0;
int iuantu = 0; // pocet cisel
int puantu = 0; // pocet roku
for (unsigned int i = 0; i < rokys.size();i++)
{
c = years[i];
if ((c == ',' )&& (rokys.at(i+1) == ',' || rokys.at(i+1) == '-'))
{
return EASTER_INVALID_YEARS;
}
if ((c == '-' )&& (rokys.at(i+1) == ',' || rokys.at(i+1) == '-'))
{
return EASTER_INVALID_YEARS;
}
if (c >= '0' && c <= '9')
{
rokyz.at(i) = c;
rokpole[quantu] = c;
quantu++;
}
else if (c == ',')
{
rokyz.at(i) = ',';
}
else if (c == ' ')
{
}
else if (c == '-')
{
rokyz.at(i) = '-';
interval++;
/* for (int q = 0; q < 4; q++)
{
prvni[q] = rokyz.at(i-j);
j--;
}
j++;
for (int q = 0; q < 4; q++)
{
druhy[q] = rokyz.at(i+j);
j++;
}
cout << '\n';
cout << prvni << endl;
cout << druhy << endl;
int paprika = atoi(prvni);
int jablko = atoi(druhy);
interval = jablko - paprika;
cout << interval;
*/
}
else
{
return EASTER_INVALID_YEARS;
}
if(quantu == 4)
{
rokypole[iuantu]= atoi(rokpole);
iuantu++;
puantu++;
intervalsingle++;
quantu = 0;
}
}
cout << "single interval je:" << intervalsingle-2;
interval = intervalsingle-2;
if(interval != 0)
{
vysinter = rokypole[interval+1]-rokypole[interval];
int pocet = interval;
cout <<endl;
cout << "interval "<< interval<<endl;
cout << "vysledek intervalu " <<vysinter<<endl;
for(int o = 0; o <= vysinter; o++)
{
rokypole[interval+o] = rokypole[interval]+o;
pocet++;
}
for(int i = 0; i < pocet; i++)
{
cout << rokypole[i]<<endl;
}
cout << "pocet cisel je: " << pocet << '\n';
}
else
{
cout << endl;
for(int i = 0; i < iuantu; i++)
{
cout << rokypole[i]<<endl;
}
}
/*
string input = "2015,2016,2017,2018,2019,2017,2018,2019, 2020-2030";
cout << '\n';
istringstream ss(input);
string line;
while (getline(ss, line, ','))
{
size_t pos;
if ((pos = line.find('-')) == string::npos)
{
cout << "single: " << line << endl;
}
else
{
cout << "range from: "
<< line.substr(0, pos)
<< " to "
<< line.substr(pos+1) << endl;
}
}
*/
if(checkyear(years) != EASTER_OK)
return EASTER_INVALID_YEARS;
return EASTER_OK;
}
#ifndef __PROGTEST__
int main ()
{
int s = easterReport( "2001, 2020-2030", "g.html" );
printf("\nreturn code: %d\n",s);
return EASTER_OK;
}
#endif /* __PROGTEST__ */
|