diff options
| author | Aditya Naik | 2018-05-10 00:44:54 -0400 |
|---|---|---|
| committer | Aditya Naik | 2018-05-10 00:44:54 -0400 |
| commit | 893beff3693644ca99ae16aa505aac06f2733ab6 (patch) | |
| tree | 8686c2ed4df12869710a16d801fe71e52ac4bcf0 | |
| parent | a2a760042186b900752014025dd5f3d3bafcfd19 (diff) | |
added few older solution files
| -rwxr-xr-x | 10284/fen.cpp | 183 | ||||
| -rwxr-xr-x | 10284/fen.in | 25 | ||||
| -rwxr-xr-x | 11498/ngolia.cpp | 27 | ||||
| -rwxr-xr-x | 11727/cost.cpp | 27 | ||||
| -rw-r--r-- | README | 1 |
5 files changed, 263 insertions, 0 deletions
diff --git a/10284/fen.cpp b/10284/fen.cpp new file mode 100755 index 0000000..5daecd5 --- /dev/null +++ b/10284/fen.cpp @@ -0,0 +1,183 @@ +#include <iostream>
+#include <string>
+#include <ctype.h>
+#include <stdlib.h>
+using namespace std;
+
+/*
+legend:
+f: free
+a: attacked
+P/p: pawn
+B/b: bishop
+N/n: knight
+R/r: rook
+Q/q: queen
+K/k: king
+ */
+
+void addrookattack(string board[8][8], int row, int col);
+void addbishopattack(string board[8][8], int row, int col);
+void addattack(string board[8][8], string piece, int row, int col);
+void printboard(string board[8][8]);
+
+int main(){
+ string board[8][8];
+ string fen;//="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
+ while(cin>>fen){
+ int row=0, col=0, index=0;
+ while(row<8){
+ int frees;
+ while(fen[index]!='/' && fen[index]!=NULL){
+ if(isdigit(fen[index])){
+ frees=fen[index]-'0'+col;
+ while(col<frees){board[row][col]="f"; col++; }
+ index++;
+ }
+ else{
+ board[row][col]=fen[index];
+ col++;
+ index++;
+ }
+ }
+ row++;index++;col=0;
+ }
+ //for(row=0;row<8;row++){
+ //cout<<endl;
+ //for(col=0;col<8;col++)
+ //cout<<board[row][col];
+
+ row=col=0;
+ while(row<8){
+ if(board[row][col]=="f" || board[row][col]=="a");
+ else addattack(board, board[row][col], row, col);
+ col++;
+ if(col>7) { row++;col=0; }
+ }
+ // printboard(board);
+ int counter=0;
+ for(row=0;row<8;row++)
+ for(col=0;col<8;col++)
+ if(board[row][col]=="f") counter++;
+ cout<<counter<<endl;
+ }
+ return 0;
+}
+
+void addattack(string board[8][8], string piece, int row, int col){
+
+ if(piece=="k" || piece=="K") {
+
+ if(col+1<=7 && board[row][col+1]=="f") board[row][col+1]="a";
+ if(col-1>=0 && board[row][col-1]=="f") board[row][col-1]="a";
+
+ if(row+1<=7){
+ if(board[row+1][col]=="f") board[row+1][col]="a";
+ if(col+1<=7 && board[row+1][col+1]=="f") board[row+1][col+1]="a";
+ if(col-1>=0 && board[row+1][col-1]=="f") board[row+1][col-1]="a";
+ }
+ if(row-1>=0){
+ if(board[row-1][col]=="f") board[row-1][col]="a";
+ if(col+1<=7 && board[row-1][col+1]=="f") board[row-1][col+1]="a";
+ if(col-1>=0 && board[row-1][col-1]=="f") board[row-1][col-1]="a";
+ }
+ }
+
+ else if(piece=="q" || piece=="Q") {
+ addrookattack(board, row, col);
+ addbishopattack(board, row, col);
+ }
+ else if(piece=="b" || piece=="B") { addbishopattack(board, row, col); }
+ else if(piece=="r" || piece=="R") { addrookattack(board, row, col); }
+ else if(piece=="n" || piece=="N") {
+ if(row+2<=7 && col+1<=7 && board[row+2][col+1]=="f") board[row+2][col+1]="a";
+ if(row+2<=7 && col-1>=0 && board[row+2][col-1]=="f") board[row+2][col-1]="a";
+ if(row-2>=0 && col+1<=7 && board[row-2][col+1]=="f") board[row-2][col+1]="a";
+ if(row-2>=0 && col-1>=0 && board[row-2][col-1]=="f") board[row-2][col-1]="a";
+
+ if(col+2<=7 && row+1<=7 && board[row+1][col+2]=="f") board[row+1][col+2]="a";
+ if(col+2<=7 && row-1>=0 && board[row-1][col+2]=="f") board[row-1][col+2]="a";
+ if(col-2>=0 && row+1<=7 && board[row+1][col-2]=="f") board[row+1][col-2]="a";
+ if(col-2>=0 && row-1>=0 && board[row-1][col-2]=="f") board[row-1][col-2]="a";
+ }
+ else if(piece=="p"){
+ if(row+1<8 && col-1>=0 && board[row+1][col-1]=="f") board[row+1][col-1]="a";
+ if(row+1<8 && col+1<=7 && board[row+1][col+1]=="f") board[row+1][col+1]="a";
+ }
+ else if(piece=="P"){
+ if(row-1>=0 && col+1<=7 && board[row-1][col+1]=="f") board[row-1][col+1]="a";
+ if(row-1>=0 && col-1>=0 && board[row-1][col-1]=="f") board[row-1][col-1]="a";
+ }
+}
+
+void printboard(string board[8][8]){
+ for(int r=0;r<8;r++){
+ for(int c=0;c<8;c++){
+ cout<<board[r][c]<<" ";
+ }
+ cout<<endl;
+ }
+}
+
+
+void addbishopattack(string board[][8],int row, int col){
+ bool conf=false;
+ int trow=row, tcol=col;
+ while(!conf){
+ tcol++;trow++;
+ if(tcol>=8 || trow>=8 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row;tcol=col;
+ while(!conf){
+ tcol++;trow--;
+ if(tcol>=8 || trow<0 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row; tcol=col;
+ while(!conf){
+ tcol--;trow--;
+ if(tcol<0 || trow<0 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row; tcol=col;
+ while(!conf){
+ tcol--;trow++;
+ if(tcol<0 || trow>=8 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+}
+
+void addrookattack(string board[][8], int row, int col){
+ bool conf=false;
+ int trow=row, tcol=col;
+ while(!conf){
+ trow++;
+ if(trow>=8 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row; tcol=col;
+ while (!conf){
+ trow--;
+ if(trow<0 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row; tcol=col;
+ while (!conf){
+ tcol++;
+ if(tcol>=8 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+ conf=false;
+ trow=row;tcol=col;
+ while (!conf){
+ tcol--;
+ if(tcol<0 || (board[trow][tcol]!="f" && board[trow][tcol]!="a")) conf=true;
+ else board[trow][tcol]="a";
+ }
+}
diff --git a/10284/fen.in b/10284/fen.in new file mode 100755 index 0000000..8d5ef93 --- /dev/null +++ b/10284/fen.in @@ -0,0 +1,25 @@ +8/8/8/8/3b4/8/8/8
+8/8/8/8/3B4/8/8/8
+8/8/8/8/3r4/8/8/8
+8/8/8/8/3R4/8/8/8
+8/8/8/8/3q4/8/8/8
+8/8/8/8/3Q4/8/8/8
+8/8/8/8/3n4/8/8/8
+8/8/8/8/3N4/8/8/8
+8/8/8/8/3k4/8/8/8
+8/8/8/8/3K4/8/8/8
+8/8/8/8/3p4/8/8/8
+8/8/8/8/3P4/8/8/8
+8/8/8/3Q4/3N4/8/8/8
+8/8/8/8/7B/6N1/8/7R
+8/8/8/8/1p1p1p2/8/P1P1P1P1/8
+5k1r/2q3p1/p3p2p/1B3p1Q/n4P2/6P1/bbP2N1P/1K1RR3
+8/8/8/8/8/8/8/7r
+rrrrrrrr/8/8/8/8/8/8/8
+1n1n1n1n/n1n1n1n1/1n1n1n1n/n1n1n1n1/1n1n1n1n/n1n1n1n1/1n1n1n1n/n1n1n1n1
+n7/8/8/8/8/8/8/7N
+Q7/8/8/8/8/8/8/8
+Qp6/PP6/8/8/8/8/8/8
+Kp6/PP6/8/8/8/8/8/8
+Bp6/PP6/8/8/8/8/8/8
+Np6/PP6/8/8/8/8/8/8
diff --git a/11498/ngolia.cpp b/11498/ngolia.cpp new file mode 100755 index 0000000..a744b42 --- /dev/null +++ b/11498/ngolia.cpp @@ -0,0 +1,27 @@ +#include <iostream>
+using namespace std;
+
+int main(){
+ int inct;
+ int origx, origy;
+ int x, y;
+ cin>>inct;
+ while(inct!=0)
+ {
+ int loccnt=0;
+ cin>>origx>>origy;
+ while(loccnt<inct)
+ {
+ cin>>x>>y;
+ x-=origx;y-=origy;
+ if(x==0 || y==0) cout<<"divisa"<<endl;
+ else if(x>0 && y>0) cout<<"NE"<<endl;
+ else if(x>0 && y<0) cout<<"SE"<<endl;
+ else if(x<0 && y>0) cout<<"NO"<<endl;
+ else if(x<0 && y<0) cout<<"SO"<<endl;
+ loccnt++;
+ }
+ cin>>inct;
+ }
+ return 0;
+}
diff --git a/11727/cost.cpp b/11727/cost.cpp new file mode 100755 index 0000000..69dded2 --- /dev/null +++ b/11727/cost.cpp @@ -0,0 +1,27 @@ +#include <iostream>
+using namespace std;
+
+int main(){
+ int ct, x=0, ar[3], temp;
+ cin>>ct;
+ while(x<ct)
+ {
+ cin>>ar[0]>>ar[1]>>ar[2];
+ bool sorted=false;
+ while(!sorted)
+ for(int i=1;i<3;i++)
+ {
+ sorted=true;
+ if(ar[i]<ar[i-1])
+ {
+ sorted=false;
+ temp=ar[i-1];
+ ar[i-1]=ar[i];
+ ar[i]=temp;
+ }
+ }
+ cout<<"Case "<<x+1<<": "<<ar[1]<<endl;;
+ x++;
+ }
+}
+
@@ -0,0 +1 @@ +http://uhunt.onlinejudge.org/id/477555
\ No newline at end of file |
