#include <stdio.h> int main(void) { int n,k,i; char c; scanf("%d",&n); while(n--){ scanf("%1s%d",&c,&k); if((c=='a'||c=='h')&&(k==1||k==8)) {printf("2\n"); continue;} if((c=='a'||c=='h')&&(k==2||k==7)) {printf("3\n"); continue;} if((c=='b'||c=='g')&&(k==1||k==8)) {printf("3\n"); continue;} if((c=='b'||c=='g')&&(k==2||k==7)) {printf("4\n"); continue;} if(c<'b'||c>'g') {printf("4\n"); continue;} if(k<2||k>7) {printf("4\n"); continue;} if((c=='b'||c=='g') || (k==2||k==7)) {printf("6\n"); continue;} printf("8\n"); } return 0; } Edited by author 01.06.2010 16:05 import java.util.Scanner; public class _1197 { public static void main( String[] args ) { int[][] chessBoard = new int[8][8]; for( int i=0 ; i<8 ; i++ ) for( int j=0 ; j<8 ; j++ ) { int counter = 0; if( i-2>=0 && j-1>=0 ) ++counter; if( i-2>=0 && j+1<=7 ) ++counter; if( i-1>=0 && j-2>=0 ) ++counter; if( i-1>=0 && j+2<=7 ) ++counter; if( i+2<=7 && j-1>=0 ) ++counter; if( i+2<=7 && j+1<=7 ) ++counter; if( i+1<=7 && j-2>=0 ) ++counter; if( i+1<=7 && j+2<=7 ) ++counter; chessBoard[i][j] = counter; } Scanner in = new Scanner( System.in ); int N = in.nextInt(); for( int i=0 ; i<N ; i++ ) { String p = in.next(); System.out.println( chessBoard[p.charAt(0)-'a'][p.charAt(1)-'1'] ); } } } I dont think my answer is wrong since i worked it out with chess board itself. Then why WA1??? Is is something to do with output format?? please help. 10 d3 8 a8 2 h8 2 b2 4 a6 4 g5 6 e6 8 a1 2 f1 4 c3 8 Here is my solution: const dir:array[1..8,1..2] of shortint= ((2,1),(2,-1),(1,2),(1,-2),(-1,2),(-1,-2),(-2,1),(-2,-1)); var test,x,y,number,i:byte; s:string[2]; begin readln(test); while test>0 do begin dec(test); readln(s); x:=ord(s[1])-ord('a')+1; y:=ord(s[2])-ord('0'); number:=0; for i:=1 to 8 do if (x+dir[i,1]>=1)and(x+dir[i,1]<=8) and(y+dir[i,2]>=1)and(y+dir[i,2]<=8) then inc(number); writeln(number); end; end. my - the best :)))) var s:string[2]; count,x,i,q,w:integer; begin readln(x); for i:=1 to x do begin readln(s); if s[1]='a' then s[1]:='1';if s[1]='b' then s[1]:='2'; if s[1]='c' then s[1]:='3';if s[1]='d' then s[1]:='4'; if s[1]='e' then s[1]:='5';if s[1]='f' then s[1]:='6'; if s[1]='g' then s[1]:='7';if s[1]='h' then s[1]:='8'; count:=0; for q:=1 to 8 do for w:=1 to 8 do if ((q=ord(s[1])-ord('0')-1)and(w=ord(s[2])-ord('0')-2))or ((q=ord(s[1])-ord('0')-1)and(w=ord(s[2])-ord('0')+2))or ((q=ord(s[1])-ord('0')+1)and(w=ord(s[2])-ord('0')-2))or ((q=ord(s[1])-ord('0')+1)and(w=ord(s[2])-ord('0')+2))or ((q=ord(s[1])-ord('0')-2)and(w=ord(s[2])-ord('0')-1))or ((q=ord(s[1])-ord('0')-2)and(w=ord(s[2])-ord('0')+1))or ((q=ord(s[1])-ord('0')+2)and(w=ord(s[2])-ord('0')-1))or ((q=ord(s[1])-ord('0')+2)and(w=ord(s[2])-ord('0')+1)) then inc(count); writeln(count); end; end. #include <stdio.h> int p[8][8]={2,3,4,4,4,4,3,2, 3,4,6,6,6,6,4,3, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 3,4,6,6,6,6,4,3, 2,3,4,4,4,4,3,2}; void main(void) { int N; scanf("%i\n",&N); for(int i=0;i<N;i++) { char letter,digit; scanf("%c%c\n",&letter,&digit); int il,id; il=letter-'a'+1; id=digit-'0'; printf("%i\n",p[il-1][id-1]); } } 19 lines AC))) var N,a,b,i:integer; c:char; begin readln(N); for i:=1 to N do begin read(c); a:=ord(c)-ord('a')+1; if a>4 then a:=9-a; if a=4 then a:=3; readln(b); if b>4 then b:=9-b; if b=4 then b:=3; if a+b>4 then inc(a); if a+b>6 then inc(a); writeln(a+b); end; end. program p1197; var st:string; n,i:byte; procedure sort1; begin if (st[2]='1') or (st[2]='8') then begin writeln(2); exit; end; if (st[2]='2') or (st[2]='7') then begin writeln(3); exit; end; writeln(4); exit; end; procedure sort2; begin if (st[2]='1') or (st[2]='8') then begin writeln(3); exit; end; if (st[2]='2') or (st[2]='7') then begin writeln(4); exit; end; writeln(6); exit; end; procedure sort3; begin if (st[2]='1') or (st[2]='8') then begin writeln(4); exit; end; if (st[2]='2') or (st[2]='7') then begin writeln(6); exit; end; writeln(8); exit; end; begin readln(n); for i:=1 to n do begin readln(st); if (st[1]='a') or (st[1]='h') then begin sort1; end; if (st[1]='b') or (st[1]='g') then begin sort2; end; if (st[1]='c') or (st[1]='d') or (st[1]='e') or (st[1]='f') then begin sort3; end; end; end. This problem is too simple! Why its is volume 2??? Volume number is not hardness of problems. It is just page number. Edited by author 09.12.2006 16:40 Maybe I did incorrect output? #include <stdio.h> int a[100][100]={{2,3,4,4,4,4,3,2}, {3,4,6,6,6,6,4,3}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {3,4,6,6,6,6,4,3}, {2,3,4,4,4,4,3,2}}; int b[102]; int trans(char c1); int i=0,n,y,x,j; char c; int main() {
scanf("%d",&n); for(i=0;i<n;i++) { b[i]=0; fflush( stdin ); scanf("%c",&c); x=trans(c)-1; scanf("%c",&c); y=trans(c)-1; fflush( stdin ); b[i]=a[x][y]; } for(i=0;i<n;i++) printf("%d\n",b[i]); return 0; } int trans(char c1) { int x1; switch(c) { case 'a': x=1; break; case 'b': x=2; break; case 'c': x=3; break; case 'd': x=4; break; case 'e': x=5; break; case 'f': x=6; break; case 'g': x=7; break; case 'h': x=8; break; case '1': x=1; break; case '2': x=2; break; case '3': x=3; break; case '4': x=4; break; case '5': x=5; break; case '6': x=6; break; case '7': x=7; break; case '8': x=8; break; } return x1; } just write x1 instead of x in subroutine trans int trans(char c1) { int x1;//<--!!! switch(c) { case 'a': x=1; break;//! case 'b': x=2; break;//! case 'c': x=3; break;//! //... case '8': x=8; break;//! } return x1;//<--!!! } OMG! Isn`t there Visual Studio compiler? I'll know this feature at future, thanks. dx[8]={1,2,2,1,-1,-2,-2,-1},dy[8]={2,1,-1,-2,-2,-1,1,2}; ...... cin>>in;
for(i=0;i<8;i++) { if(aa[i]==in[0]) {a=i;}
} for(i=0;i<8;i++) { if(bb[i]==in[1]) {b=i;}
} ..... I write program on C++ [code deleted] I Submited it and WA1 After I submited program from this forum - AC I tested programs, they give correct equal answers. Why WA1? File of output of my program equal file of output forum's program. Please, Help Edited by moderator 08.08.2006 17:35 Maybe you are don't correctly show answer Edited by author 06.08.2006 23:32 int t1, t2; scanf("%c%c%d", &t1, &t1, &t2); It's wrong. First of all %c means char, 1 byte. So you have not fully initialized t1, as it is not global variable and not initialized with zero. And of course it's not good way to read input, what if there is an extra space in the end of a line? It's a text file after all ;) And imho there is no reason to write (int argc, char* argv[]) Edited by author 07.08.2006 13:25 Hello! I don't have any errors on my computer, but when i'm trying to submit the problem i get a compilation error. Does anyone know why? Here is my code: #include <iostream> #include <string.h> using namespace std; int main() { int IloscPol,i; int MozliwoscRuchow[100]; string Pola[100];
cin>>IloscPol; for( i=0 ; i<IloscPol ; i++) { cin>>Pola[i]; if (Pola[i]=="a1" || Pola[i]=="a8" || Pola[i]=="h8" || Pola[i]=="h1" ) MozliwoscRuchow[i]=2; else if (Pola[i]=="a2" || Pola[i]=="b1" || Pola[i]=="g1" || Pola[i]=="h2" || Pola[i]=="a7" || Pola[i]=="b8" || Pola[i]=="g8" || Pola[i]=="h7") MozliwoscRuchow[i]=3; else if (Pola[i]=="a3" || Pola[i]=="a4" || Pola[i]=="a5" || Pola[i]=="a6" || Pola[i]=="c1" || Pola[i]=="d1" || Pola[i]=="e1" || Pola[i]=="f1" || Pola[i]=="c8" || Pola[i]=="d8" || Pola[i]=="e8" || Pola[i]=="f8" || Pola[i]=="h3" || Pola[i]=="h4" || Pola[i]=="h5" || Pola[i]=="h6" || Pola[i]=="b2" || Pola[i]=="b7" || Pola[i]=="g2" || Pola[i]=="g7") MozliwoscRuchow[i]=4; else if (Pola[i]=="b3" || Pola[i]=="b4" || Pola[i]=="b5" || Pola[i]=="b6" || Pola[i]=="c2" || Pola[i]=="d2" || Pola[i]=="e2" || Pola[i]=="f2" || Pola[i]=="c7" || Pola[i]=="d7" || Pola[i]=="e7" || Pola[i]=="f7" || Pola[i]=="g3" || Pola[i]=="g4" || Pola[i]=="g5" || Pola[i]=="g6") MozliwoscRuchow[i]=6; else MozliwoscRuchow[i]=8; } for (i=0 ; i<IloscPol ; i++) cout<<MozliwoscRuchow[i]<<endl; system("pause"); } >>system("pause"); skasuj to :) What an output format must be? Are there /n between the outputs? please can anybody provide me with test cases??mine is failinf in test 1. please help me with test cases why the judge is not acccepting my solution?? Anyone here knows how to play chess? For g6 it is NOT 6, it IS 4! From g6 knight can move to h8,h6,f8,f6,e7,e5 - so, six moves You guys are mocking me... We are talking about a KNIGHT! How can a KNIGHT(!) from g6 can move to h6?!?!?!?!?! Edited by author 04.10.2005 01:11 I'm sorry instead of h6 is h4 and instead of f6 is f4 Aha! That's a different thing... Ok... Thanks... Um...Yes, they are 6 moves... But I still have a problem with #test2 Here is my prgram: #include<iostream.h> int the_board[16][16]; char place[2]; int i, j, counter, N, k, l; void enter() { cin>>place; i = place[1] - '0'; k = i-1; if ( place[0] == 'a' ) j = 1; if ( place[0] == 'b' ) j = 2; if ( place[0] == 'c' ) j = 3; if ( place[0] == 'd' ) j = 4; if ( place[0] == 'e' ) j = 5; if ( place[0] == 'f' ) j = 6; if ( place[0] == 'g' ) j = 7; if ( place[0] == 'h' ) j = 8; l = j-1; } void calculate() { for( i = 0;i < 14;i++ ) for( j = 0;j < 14;j++ ) the_board[i][j] = 0; the_board[k][l] = 1; the_board[k-2][l-1] = 2; the_board[k-2][l+1] = 2; the_board[k+2][l+1] = 2; the_board[k+2][l-1] = 2; the_board[k+1][l+2] = 2; the_board[k-1][l+2] = 2; the_board[k+1][l-2] = 2; the_board[k-1][l-2] = 2; for( i = 0;i < 8;i++ ) for( j = 0;j < 8;j++ ) if ( the_board[i][j] == 2 ) counter++; } void main() { int re_counter[100]; for( int h = 0;h < 100;h++ ) re_counter[h] = 0; cin>>N; for( int i = 0;i < N;i++ ) { enter(); calculate(); if ( re_counter[i] == 0 ) re_counter[i] = counter; counter = 0; } for( i = 0;i < N;i++ ) cout<<re_counter[i]<<endl; } What is wrong with it??? I tried to solve problem 1197. And in my computer there is no error in compiling. Even the answer is correctly given. But the online judge replies: You tried to solve problem 1197. Your solution on C++ was compiled with the following errors: 406816 e:\Judge\vc7\include\useoldio.h(29) : warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma deprecated temp\406816(75) : fatal error C1075: end of file found before the left brace '{' at 'temp\406816(8)' was matched С I can’t understand. Where is my mistake? Will you help me? Here is my program: #include<iostream.h> #include<stdio.h> char cell[2]; int i,set,don,number,position[8],possible; main() { while(cin>>set){ for(don=1;don<=set;don++){ scanf("\n%s",&cell); switch(cell[0]) { case 'a':number=0; break; case 'b':number=10; break; case 'c':number=20; break; case 'd':number=30; break; case 'e':number=40; break; case 'f':number=50; break; case 'g':number=60; break; case 'h':number=70; break; } switch(cell[1]) { case '1':number=number+1; break; case '2':number=number+2; break; case '3':number=number+3; break; case '4':number=number+4; break; case '5':number=number+5; break; case '6':number=number+6; break; case '7':number=number+7; break; case '8':number=number+8; break; } position[0]=number-12; position[1]=number+12; position[2]=number+21; position[3]=number-21; position[4]=number+8; position[5]=number-8; position[6]=number+19; position[7]=number-19; possible=0; for(i=0;i<8;i++) { if(position[i]>0 && ((position[i]%10)!=9)) { if( ((position[i]%10)!=0) && position[i]<79){ possible++; } } } number=0; cout<<possible<<endl; } } return 0; } you have a very ugly program Read my AC source program lonesome; const dx:array[1..8]of integer =(1,2,2,1,-1,-2,-2,-1); dy:array[1..8]of integer =(2,1,-1,-2,-2,-1,1,2); var strr:string[2]; num,n,i,x,y:integer; procedure solve(x,y:integer); var i,tempx,tempy:integer; begin for i:=1 to 8 do begin tempx:=x+dx[i]; tempy:=y+dy[i]; if (tempx>=1) and (tempx<=8) then if (tempy>=1) and (tempy<=8) then inc(num); end; end; begin readln(n); for i:=1 to n do begin readln(strr); x:=ord(strr[1])-ord('a')+1; y:=ord(strr[2])-ord('0'); num:=0; solve(x,y); writeln(num); end; end. |
|