Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481959
  • 博文数量: 59
  • 博客积分: 345
  • 博客等级: 二等列兵
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-18 22:44
个人简介

to be myself

文章分类

全部博文(59)

文章存档

2017年(5)

2013年(47)

2012年(3)

2011年(4)

分类: C/C++

2013-03-02 18:22:10


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <string.h>

  3. int main()
  4. {
  5.     int n = 8, i = 0, flag = 0, j = 0, z = 0, ans = 1, count;
  6.     char? str[35], search[2][7]={"KQRBNP","kqrbnp"}, *p, col, chess[8][35];
  7.     
  8.     while(n--)
  9.     {
  10.         scanf("%s%s", str,str); //连续读两次,把边界+---+row丢掉
  11.         strcpy(chess+n, str); //逆row存储
  12.     }
  13.     
  14.     printf("White: ");
  15.     
  16.     while(1)
  17.     {
  18.         while(i < 6)
  19.         {
  20.             count = 0;
  21.             n = z;
  22.             
  23.             while(n = z + count * ans, count < 8)
  24.             {
  25.                 if(p = (char*)memchr(chess[n], search[j][i], strlen(chess[n])))
  26.                 {
  27.                     if(flag) //第一个type前不需要逗号
  28.                     {
  29.                         printf(",");
  30.                     }
  31.                     flag++;
  32.                     if(i < 5) //是pwans则不需要输出"p""P"
  33.                     {
  34.                         printf("%c", search[0][i]);
  35.                     }
  36.                     col = (p - chess[n] - 2) / 4 + 'a'; //根据在字符串中的位置 和字符串首地址的差值算出所在column
  37.                     printf("%c%d", col, n + 1);
  38.                 }
  39.                 
  40.                 while(p) //可能一个row还没找完剩下一样的type
  41.                 {
  42.                     chess[n][p - chess[n]] = ' '; //如果一行中还有相同的type时,先将找到的那个置为空,避免重复查找
  43.                     
  44.                     p = (char*)memchr(chess[n], search[j][i], strlen(chess[n]));
  45.                     if(!p)
  46.                     {
  47.                         break;
  48.                     }
  49.                     
  50.                     printf(",");
  51.                     if(i < 5)
  52.                     {
  53.                         printf("%c", search[0][i]);
  54.                     }
  55.                     col = (p - chess[n] - 2) / 4 + 'a';
  56.                     printf("%c%d", col, n + 1);
  57.                 }
  58.                 count++; //按照01234567, 76543210的顺序分别找white和black
  59.             }
  60.             i++;
  61.         }
  62.         
  63.         if(j == 1)
  64.         {
  65.             break;
  66.         }
  67.         
  68.         printf("nBlack: ");
  69.         flag = i = 0;
  70.         ans = -1;
  71.         z = 7;
  72.         j++;
  73.     }
  74.     printf("n");
  75.     
  76.     return 0;
  77. }

Problem:User:Memory: 144KTime: 0MSLanguage: CResult:Accepted


2011-04-09 00:20 发表于百度空间,今搬至CU。

阅读(1961) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~