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
|
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
ifstream fin("beads.in");
ofstream fout("beads.out");
int numbeads, tempblue=0, tempred=0, total=0, b=0, r=0, redcounter=20, bluecounter=20;
char lastcolor;
fin>>numbeads;
vector<int> red(numbeads);
vector<int> blue(numbeads);
vector<char> beadcolors(numbeads);
//f-ins the color values
for(int j=0;j<numbeads;j++)
{
fin>>beadcolors[j];
}
//calculates number of beads
for(int j=0;j<numbeads;j++)
{
if(j>=0&&j<55)
{
cout<<"j is "<<j<<"\n";
cout<<"redcounter is "<<redcounter<<"\n";
}
//if bead is blue
if(beadcolors[j]=='b')
{
if(beadcolors[j-1]=='r'||(beadcolors[j-1]=='w'&&redcounter==0)||j==0)
{
if(j==0)
{
lastcolor='r';
tempblue=0;
blue[0]=0;
red[0]=0;
tempred=0;
}
redcounter=0;
bluecounter=0;
tempblue=red[r-1];
}
blue[b]++;
redcounter++;
if(beadcolors[j+1]=='r'||(j+1)==numbeads)
{
tempblue+=blue[b];
if((j+1)==numbeads)
{
if((beadcolors[0]=='b'||beadcolors[0]=='w')&&r!=0)
{
cout<<"HELLOOOOOOOOOO!";
tempblue+=blue[0];
}
}
if(tempblue>total)
{
total=tempblue;
}
b++;
bluecounter=0;
lastcolor='b';
tempred=0;
red[r]=0;
}
}
//if bead is red
if(beadcolors[j]=='r')
{
if(beadcolors[j-1]=='b'||(beadcolors[j-1]=='w'&&bluecounter==0)||j==0)
{
tempred=blue[b-1];
red[r]=0;
bluecounter=0;
if(j==0)
{
lastcolor='b';
tempblue=0;
blue[0]=0;
red[0]=0;
tempred=0;
}
}
red[r]++;
bluecounter++;
if(beadcolors[j+1]=='b'||(j+1)==numbeads)
{
redcounter=0;
tempred+=red[r];
if((j+1)==numbeads)
{
if((beadcolors[0]=='r'||beadcolors[0]=='w')&&b!=0)
{
tempred+=red[0];
}
}
if(tempred>total)
{
total=tempred;
}
r++;
tempblue=0;
blue[b]=0;
lastcolor='r';
}
}
//if bead is white
if(beadcolors[j]=='w')
{
blue[b]++;
red[r]++;
if(lastcolor=='b'&&beadcolors[j+1]=='b')
{
redcounter=0;
tempred+=red[r];
if((j+1)==numbeads)
{
if((beadcolors[0]=='r'||beadcolors[0]=='w')&&b!=0)
{
tempred+=red[0];
}
}
if(tempred>total)
{
total=tempred;
}
r++;
red[r]=0;
tempblue=0;
lastcolor='r';
}
if(lastcolor=='r'&&beadcolors[j+1]=='r')
{
bluecounter=0;
tempblue+=blue[b];
if((j+1)==numbeads)
{
if((beadcolors[0]=='b'||beadcolors[0]=='w')&&r!=0)
{
tempblue+=blue[0];
}
}
if(tempblue>total)
{
total=tempblue;
}
b++;
blue[b]=0;
tempred=0;
lastcolor='b';
}
if(lastcolor=='r'&&beadcolors[j-1]!='r')
{
cout<<"HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
cout<<"j-1=="<<beadcolors[j-1];
redcounter++;
}
if(lastcolor=='b'&&beadcolors[j-1]!='b')
{
bluecounter++;
}
}
if(j>=0&&j<55)
{
cout<<"tempblue is "<<tempblue<<"\n";
cout<<"tempred is "<<tempred<<"\n";
cout<<"blue is "<<blue[b]<<"\n";
cout<<"red is "<<red[r]<<"\n";
cout<<"redcounter is "<<redcounter<<"\n";
cout<<"bluecounter is "<<bluecounter<<"\n";
cout<<"lastcolor is "<<lastcolor<<"\n";
cout<<"total is "<<total<<"\n\n";
}
}
fout<<total<<"\n";
/*
use if to add 1 to temp(color) and also erases other color value
if j+1 is other color, and temp(color) is greater than (color), then (color) is =
to temp(color)
take total of past group, and add it to temptotal, and then at the end, take
current value and add to temp total, and if it is the highest, then it is
the total. For the first group, put their total in a different variable,
and then if the last grouping is the same color, then it is added to their
subtotal
(color)counter counts how many runs have passed since end of (color)
[PROBLEM:in one run, last color needs to be done after the condition for the function, but in the other
the blue counter can not start until last color is activated]
[Solution:]
adds both colors together and fouts the total
*/
system ("PAUSE");
return 0;
}
|