homework-04 抓瞎

程序截图

这是基本版本截图。。。。空都没填上

四个角的话 可以留下四个单词 最后添上就行

 

 

 程序思路

在一个大平面上先一个中心,然后从中心向四周填词

每次填词时,寻找一个使得矩阵最小的

代目如下

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define WORDLEN 12
#define MID 15
#define UP 0
#define UP_R 1
#define RIGHT 2
#define DOWN_R 3
#define DOWN 4
#define DOWN_L 5
#define LEFT 6
#define UP_L 7

int debug = 1;
char dictionary[100][WORDLEN];
char Word[100][100];
int dictSign[100]={0};
int dictSize;
int a[2];

static void
readDictionary(char *dictName)
{
    FILE *h;
    char s[80];
    int i;

    dictSize = 0;
    h = fopen(dictName, "rt");
    fgets(s, 80, h);
    while (!feof(h)) {
        s[strlen(s)-1] = '\0';  /* get rid of newline */
            strcpy(dictionary[dictSize++], s);
        fgets(s, 80, h);
    }
    printf("Dictionary size is %d\n", dictSize);

    for(i=0; i<dictSize; i++){
        printf("%s\n",dictionary[i]);
    }
}

int getMax(){
    int max=0,which=0;
    int all=0;
    for(int i=0; i<dictSize; i++){
        if(dictSign[i] == 1)
            continue;
        int len = strlen(dictionary[i]);
        if(max < len){
            max = len;
            which = i;
            all = 1;
            dictSign[i] = 1;
        }
    }
    if(all == 0)
        return -1;
    return which;
}

bool input(int x,int y,char *s,int direction){
    int len = strlen(s);

    switch(direction){
    case UP :
        for(int i=0; i<len; i++){
            if(s[i] != Word[x-i][y] && Word[x-i][y] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x-i][y]=s[i];
        break;
    case UP_R:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x-i][y+i] && Word[x-i][y+i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x-i][y+i]=s[i];
        break;
    case RIGHT:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x][y+i] && Word[x][y+i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x][y+i]=s[i];
        break;
    case DOWN_R:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x+i][y+i] && Word[x+i][y+i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x+i][y+i]=s[i];
        break;
    case DOWN:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x+i][y] && Word[x+i][y] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x+i][y]=s[i];
        break;
    case DOWN_L:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x+i][y-i] && Word[x+i][y-i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x+i][y-i]=s[i];
        break;
    case LEFT:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x][y-i] && Word[x][y-i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x][y-i]=s[i];
        break;
    case UP_L:
        for(int i=0; i<len; i++){
            if(s[i] != Word[x-i][y-i] && Word[x-i][y-i] != 0)
                return false;
        }
        for(int i=0; i<len; i++)
            Word[x-i][y-i]=s[i];
        break;
    }
    return true;
}

void getWhere(int n){
    int layer;
    int n8=0;
    for(int i=1; ;i++){
        n8 += i*8;
        if(n <= n8){
            layer = i;
            n8 -= i*8;
            n = n-n8;
            int many = (n-1)/(i*2);

            switch(many){
                case 0:
                    a[0] = MID-i-1+n;
                    a[1] = MID-i;
                    break;
                case 1:
                    a[1] = MID-i+(n-1)%(i*2);
                    a[0] = MID+i;
                    break;
                case 2:
                    a[0] = MID+i-(n-1)%(i*2);
                    a[1] = MID+i;
                    break;
                case 3:
                    a[1] = MID+i-(n-1)%(i*2);
                    a[0] = MID-i;
                    break;
            }
            break;
        }
    }
}
int getDirect(int x, int y){
    if(x>MID){
        if(y>MID)
            return DOWN_L;
        else if(y==MID)
            return LEFT;
        else
            return UP_L;
    }
    else if(x == MID){
        if(y > MID)
            return DOWN;
        else
            return UP;
    }
    else{
        if(y>MID)
            return DOWN_R;
        else if(y==MID)
            return RIGHT;
        else
            return UP_R;
    }
}

void ws_maker(){
    //printf("%d\n",getMax());
    char *s = dictionary[0];
    input(MID,MID,s,DOWN);
    //printf("%s\n",s);
    
    for(int i=0,j=1; i<dictSize-1;i++){
        int judge=0;
        s = dictionary[i+1];

        if(debug){
            printf("%d %s\n",i,s);
        }
        for(; ;j++){
            getWhere(j);
            int startD = (getDirect(a[0],a[1])+1)%8;
            for(int k=1; k<=8; k++){
                if(input(a[0],a[1],s,startD%8)){
                    judge = 1;
                    break;
                }
            }
            if(judge == 1)
                break;
        }
    }
}



int main(int argc, char **argv)
{
    //printf("sb%s%d\n",*argv,argc);
    /* read in the dictionary */
    readDictionary(argv[1]);
    ws_maker();
    //input(8,2,"love",UP);
    //input(8,1,"fove",UP_R);
    if(debug)
    for(int i=0; i<30; i++){
        for(int j=0; j<30; j++)
            printf("%C",Word[i][j]);
        printf("\n");
    }

}

 

 

 

 

Personal Software Process Stages

时间百分比(%)

实际花费的时间 (分钟)

原来估计的时间 (分钟)

Planning

计划

 20

 30

 0

·         Estimate

·         估计这个任务需要多少时间,把工作细化并大致排序

 20

 30

 0

Development

开发

 60

 90

 70

·         Analysis

·         需求分析 (包括学习新技术)

 10

 15

 0

·         Design Spec

·         生成设计文档

 0

 0

 0

·         Design Review

·         设计复审 (和同事审核设计文档)

 0

 0

 0

·         Coding Standard

·         代码规范 (制定合适的规范)

 0

 0

 0

·         Design

·         具体设计

 5

 7.5

 10

·         Coding

·         具体编码

20

30

 45

·         Code Review

·         代码复审

 5

 7.5

 10

·         Test

·         测试(自我测试,修改代码,提交修改)

 20

30

 5

Reporting

总结报告

 20

30

 30

·         Test Report

·         测试报告

10

 15

 10

·         Size Measurement

·         计算工作量

 5

7.5

 10

·         Postmortem & Improvement Plan

·         事后总结, 并提出改进

 5

7.5

 10

Total

总计

100%

总用时150

总估计的用时 100

转载于:https://www.cnblogs.com/rocbomb/p/3392924.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值