zoukankan      html  css  js  c++  java
  • poj2993 poj2996

    http://poj.org/problem?id=2996

    http://poj.org/problem?id=2993

    2993

     1 #include<stdio.h>
     2 #include<string.h>
     3 char map[10][10];
     4 int main()
     5 {
     6     char st[8],st1[200],st2[200];
     7     int i,j,k=1,len1,len2;
     8     for(i=0; i<2; i++)
     9     {
    10         scanf("%s",st);
    11         if(strcmp(st,"White:")==0)
    12         {
    13             getchar();
    14             gets(st1);}
    15         else{getchar();
    16             gets(st2);}
    17     }
    18     len1=strlen(st1);
    19     len2=strlen(st2);
    20     for(i=0; i<=len1; i++)
    21     {
    22         if(st1[i]==','||i==len1)
    23         {
    24             if(i==3)
    25                 map[8-(st1[i-1]-'0')][st1[i-2]-'a']=st1[i-3];
    26             else if(i==2)
    27                 map[8-(st1[i-1]-'0')][st1[i-2]-'a']='P';
    28             else
    29             {
    30                 if(st1[i-4]==',')
    31                     map[8-(st1[i-1]-'0')][st1[i-2]-'a']=st1[i-3];
    32                 else
    33                     map[8-(st1[i-1]-'0')][st1[i-2]-'a']='P';
    34             }
    35         }
    36     }
    37 
    38     for(i=0; i<=len2; i++)
    39     {
    40         if(st2[i]==','||i==len2)
    41         {
    42             if(i==3)
    43                 map[8-(st2[i-1]-'0')][st2[i-2]-'a']=st2[i-3]+32;
    44             else if(i==2)
    45                 map[8-(st2[i-1]-'0')][st2[i-2]-'a']='p';
    46             else
    47             {
    48                 if(st2[i-4]==',')
    49                     map[8-(st2[i-1]-'0')][st2[i-2]-'a']=st2[i-3]+32;
    50                 else
    51                     map[8-(st2[i-1]-'0')][st2[i-2]-'a']='p';
    52             }
    53         }
    54     }
    55     
    56     for(i=0; i<8; i++)
    57     {
    58         printf("+---+---+---+---+---+---+---+---+
    ");
    59         for(j=0; j<8; j++)
    60         {
    61             if(k)
    62             {
    63                 printf("|.");
    64                 if((map[i][j]<='a'||map[i][j]>='z')&&(map[i][j]<='A'||map[i][j]>='Z'))
    65                     printf("..");
    66                 else
    67                     printf("%c.",map[i][j]);
    68             }
    69             else
    70             {
    71                 printf("|:");
    72                 if((map[i][j]<='a'||map[i][j]>='z')&&(map[i][j]<='A'||map[i][j]>='Z'))
    73                     printf("::");
    74                 else
    75                     printf("%c:",map[i][j]);
    76             }
    77             k=!k;
    78         }
    79         printf("|
    ");
    80         k=!k;
    81     }
    82     printf("+---+---+---+---+---+---+---+---+
    ");
    83     return 0;
    84 }
    View Code

    2996

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string>
     4 #include<iostream>
     5 #include<string.h>
     6 #include<stdlib.h>
     7 using namespace std;
     8 char map[11][11];
     9 int flag=1;
    10 void findup(char c)
    11 {
    12     int i,j;
    13     for(i=8;i>=1;i--)
    14     {
    15         for(j=1;j<=8;j++)
    16         {
    17             if(map[i][j]==c)
    18             {
    19                 if(flag)
    20                     flag=0;
    21                 else
    22                     cout<<',';
    23                 if(c!='P'&&c!='p')
    24                     cout<<(char)toupper(c);
    25                 cout<<(char)(j+'a'-1)<<9-i;
    26             }
    27         }
    28     }
    29 }
    30 void findlw(char c)
    31 {
    32     int i,j;
    33     for(i=1;i<=8;i++)
    34     {
    35         for(j=1;j<=8;j++)
    36         {
    37             if(map[i][j]==c)
    38             {
    39                 if(flag)
    40                     flag=0;
    41                 else
    42                     cout<<',';
    43                 if(c!='P'&&c!='p')
    44                     cout<<(char)toupper(c);
    45                 cout<<(char)(j+'a'-1)<<9-i;
    46             }
    47         }
    48     }
    49 }
    50 int main()
    51 {
    52     int i,j;
    53     memset(map,' ',sizeof(map));
    54     string s1;
    55     getline(cin,s1);
    56     for(i=1;i<=8;i++)
    57     {
    58         string s;
    59         getline(cin,s);
    60         for(j=1;j<=8;j++)
    61         {
    62             if(isalpha(s[4*j-2]))
    63                 map[i][j]=s[4*j-2];
    64         }
    65         getline(cin,s1);
    66     }
    67     flag=1;
    68     cout<<"White: ";
    69     findup('K');
    70     findup('Q');
    71     findup('R');
    72     findup('B');
    73     findup('N');
    74     findup('P');
    75     cout<<endl<<"Black: ";
    76     flag=1;
    77     findlw('k');
    78     findlw('q');
    79     findlw('r');
    80     findlw('b');
    81     findlw('n');
    82     findlw('p');
    83     cout<<endl;
    84 }
    View Code
  • 相关阅读:
    责任链
    ITERATOR(迭代器)设计模式
    CSocket必须使用stream socket不能够使用数据报 socket
    由《win32多线程程序设计》临界区的问题所想
    JavaScript 中的FileReader对象(实现上传图片预览)
    PHP中递归的实现(附例子)
    Git 与 SVN 命令学习笔记
    Apache服务器在80端口配置多域名虚拟主机的方法
    MySQL数据表range分区例子
    MySQL主从复制技术的简单实现
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3239263.html
Copyright © 2011-2022 走看看