【无标题】2022/4/18

本文介绍如何使用C语言实现一个回文方阵,通过memset函数初始化数组,并详细解释了矩阵生成的过程。重点在于理解如何利用四个方向遍历确保数组元素的对称性。

 

回文方阵

#include<stdio.h>

#include<string.h>

int a[100][100];

int main()

{

    int n;

    while(~scanf("%d",&n)){

    memset(a,0,sizeof(a));

    int k = 1,x = 1,y = n-1,i,j;

    while(k<=n*n)

    {

        while(y<n&&!a[x][y+1]) a[x][++y] = k++;

        while(x<n&&!a[x+1][y]) a[++x][y] = k++;

        while(y>1&&!a[x][y-1]) a[x][--y] = k++;

        while(x>1&&!a[x-1][y]) a[--x][y] = k++;

    }

    for( i = 1; i <= n; i++)

    {

        for( j = 1; j <= n; j++)

            printf("%d ",a[i][j]);

        printf("\n");

    }

}

}

memset函数
memset作用是将某一块内存中的内容全部设置为指定的值,void *memset(void*s,int ch,size_t n);将s中当前位置后面的n个字节用ch替换并返回s。

包含在头文件#include<string.h>中

它常用于内存空间初始化,用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化,比如memsrt(a,'\0',sizeof(a));它是对较大的结构体或数组(通常是字符数组)进行清零操作的一种最快方法


 

请帮我写一个脚本,在Ubuntu系统下运行,用于绘制bz02测站年积日55日至63日enu坐标系下的使用rtklib进行差分定位的坐标数据的坐标时序图,读取的坐标为其中ecef坐标系下的xyz坐标,脚本尽量简单;要求剔除非固定解的数据,同时剔除相邻时间中坐标差值大于0.5m的数据,后续还要计算别的测站,要求便于修改;以下是使用rtklib进行差分定位的坐标数据文件bz020550.pos(bz02为测站名,055为年积日日期,其它pos文件命名规律相同)的部分内容:“% program : RTKPOST ver.demo5 b34d % inp file : D:\share\OBS\bz020550.22o % inp file : D:\share\OBS\bz010550.22o % inp file : D:\share\EPH\bz01\brdc0550.22n % obs start : 2022/02/24 00:00:00.0 GPST (week2198 345600.0s) % obs end : 2022/02/24 23:59:59.0 GPST (week2198 431999.0s) % pos mode : Kinematic % freqs : L1+L2/E5b % solution : Combined-Phase Reset % elev mask : 10.0 deg % dynamics : off % tidecorr : off % ionos opt : Broadcast % tropo opt : Saastamoinen % ephemeris : Broadcast % navi sys : GPS % amb res : Fix and Hold % val thres : 3.0 % antenna1 : ( 0.0000 0.0000 0.0000) % antenna2 : ( 0.0000 0.0000 0.0000) % ref pos : -1164048.8131 5062052.7932 3692813.3131 % % (x/y/z-ecef=WGS84,Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites) % GPST x-ecef(m) y-ecef(m) z-ecef(m) Q ns sdx(m) sdy(m) sdz(m) sdxy(m) sdyz(m) sdzx(m) age(s) ratio 2022/02/24 00:00:00.000 -1164022.5665 5061887.9704 3693008.2658 1 8 0.0059 0.0096 0.0075 -0.0056 0.0070 -0.0049 0.00 198.4 2022/02/24 00:00:01.000 -1164022.5688 5061887.9690 3693008.2617 1 8 0.0061 0.0096 0.0074 -0.0055 0.0070 -0.0048 0.00 198.4 2022/02/24 00:00:02.000 -1164022.5690 5061887.9691 3693008.2659 1 8 0.0042 0.0068 0.0054 -0.0038 0.0049 -0.0035 0.00 51.0 2022/02/24 00:00:03.000 -1164022.5686 5061887.9693 3693008.2660 1 8 0.0042 0.0068 0.0055 -0.0039 0.0050 -0.0035 0.00 54.2 2022/02/24 00:00:04.000 -1164022.5680 5061887.9711 3693008.2652 1 8 0.0043 0.0069 0.0055 -0.0038 0.0049 -0.0034 0.00 55.3 2022/02/24 00:00:05.000 -1164022.5667 5061887.9708 3693008.2655 1 8 0.0042 0.0068 0.0055 -0.0039 0.0049 -0.0033 0.00 56.5 2022/02/24 00:00:06.000 -1164022.5679 5061887.9695 3693008.2633 1 8 0.0042 0.0068 0.0054 -0.0038 0.0049 -0.0035 0.00 55.1 2022/02/24 00:00:07.000 -1164022.5670 5061887.9714 3693008.2658 1 8 0.0043 0.0069 0.0056 -0.0039 0.0049 -0.0036 0.00 53.0 2022/02/24 00:00:08.000 -1164022.5687 5061887.9727 3693008.2654 1 8 0.0041 0.0069 0.0054 -0.0038 0.0049 -0.0035 0.00 51.0 2022/02/24 00:00:09.000 -1164022.5681 5061887.9715 3693008.2671 1 8 0.0042 0.0068 0.0054 -0.0039 0.0049 -0.0036 0.00 51.3 2022/02/24 00:00:10.000 -1164022.5678 5061887.9714 3693008.2671 1 8 0.0042 0.0068 0.0053 -0.0039 0.0049 -0.0035 0.00 52.1 2022/02/24 00:00:11.000 -1164022.5695 5061887.9729 3693008.2662 1 8 0.0043 0.0069 0.0055 -0.0039 0.0050 -0.0035 0.00 50.9 2022/02/24 00:00:12.000 -1164022.5681 5061887.9711 3693008.2645 1 8 0.0042 0.0068 0.0054 -0.0038 0.0049 -0.0035 0.00 113.4 2022/02/24 00:00:13.000 -1164022.5679 5061887.9694 3693008.2631 1 8 0.0042 0.0068 0.0053 -0.0038 0.0050 -0.0036 0.00 126.5 2022/02/24 00:00:14.000 -1164022.5680 5061887.9688 3693008.2667 1 8 0.0042 0.0068 0.0055 -0.0038 0.0050 -0.0036 0.00 134.0 2022/02/24 00:00:15.000 -1164022.5664 5061887.9715 3693008.2653 1 8 0.0042 0.0068 0.0053 -0.0039 0.0050 -0.0036 0.00 132.0 2022/02/24 00:00:16.000 -1164022.5672 5061887.9674 3693008.2633 1 8 0.0042 0.0068 0.0052 -0.0039 0.0050 -0.0035 0.00 134.7 2022/02/24 00:00:17.000 -1164022.5671 5061887.9672 3693008.2635 1 8 0.0043 0.0068 0.0055 -0.0039 0.0049 -0.0035 0.00 131.2 2022/02/24 00:00:18.000 -1164022.5689 5061887.9741 3693008.2696 1 8 0.0042 0.0068 0.0053 -0.0039 0.0050 -0.0034 0.00 123.6 2022/02/24 00:00:19.000 -1164022.5684 5061887.9708 3693008.2632 1 8 0.0043 0.0068 0.0054 -0.0038 0.0050 -0.0036 0.00 118.3 2022/02/24 00:00:20.000 -1164022.5698 5061887.9709 3693008.2664 1 8 0.0042 0.0069 0.0054 -0.0038 0.0049 -0.0034 0.00 114.9 2022/02/24 00:00:21.000 -1164022.5716 5061887.9704 3693008.2629 1 8 0.0043 0.0068 0.0054 -0.0039 0.0049 -0.0035 0.00 113.1 2022/02/24 00:00:22.000 -1164022.5691 5061887.9736 3693008.2668 1 8 0.0043 0.0068 0.0053 -0.0040 0.0050 -0.0035 0.00 112.6 2022/02/24 00:00:23.000 -1164022.5696 5061887.9710 3693008.2639 1 8 0.0042 0.0068 0.0051 -0.0038 0.0050 -0.0035 0.00 110.0 2022/02/24 00:00:24.000 -1164022.5689 5061887.9749 3693008.2668 1 8 0.0042 0.0068 0.0055 -0.0039 0.0049 -0.0035 0.00 108.8 2022/02/24 00:00:25.000 -1164022.5662 5061887.9716 3693008.2651 1 8 0.0042 0.0068 0.0054 -0.0039 0.0050 -0.0035 0.00 106.8 2022/02/24 00:00:26.000 -1164022.5699 5061887.9711 3693008.2663 1 8 0.0042 0.0069 0.0054 -0.0038 0.0049 -0.0035 0.00 105.3 2022/02/24 00:00:27.000 -1164022.5667 5061887.9693 3693008.2642 1 8 0.0041 0.0068 0.0054 -0.0039 0.0049 -0.0035 0.00 100.1 2022/02/24 00:00:28.000 -1164022.5696 5061887.9721 3693008.2656 1 8 0.0040 0.0068 0.0055 -0.0039 0.0049 -0.0034 0.00 94.9”
05-24
This is pdfTeX, Version 3.141592653-2.6-1.40.27 (TeX Live 2025) (preloaded format=pdflatex) restricted \write18 enabled. entering extended mode (./manuscript.tex LaTeX2e <2024-11-01> patch level 2 L3 programming layer <2025-01-18> (c:/texlive/2025/texmf-dist/tex/latex/revtex/revtex4-2.cls Document Class: revtex4-2 2022/06/05 4.2f (https://journals.aps.org/revtex/ for documentation) ltxutil[2022/06/05 4.2f utilities package (portions licensed from W. E. Baxter web at superscript.com)] ltxfront[2022/06/05 4.2f frontmatter package (AO,DPC,MD)] ltxgrid[2022/06/05 4.2f page grid package (portions licensed from W. E. Baxter web at superscript.com)] (c:/texlive/2025/texmf-dist/tex/latex/revtex/aps4-2.rtx) (c:/texlive/2025/texmf-dist/tex/latex/revtex/aps12pt4-2.rtx) (c:/texlive/2025/texmf-dist/tex/latex/textcase/textcase.sty) (c:/texlive/2025/texmf-dist/tex/latex/url/url.sty) (c:/texlive/2025/texmf-dist/tex/latex/natbib/natbib.sty) (c:/texlive/2025/texmf-dist/tex/latex/revtex/revsymb4-2.sty)) (c:/texlive/2025/texmf-dist/tex/latex/ctex/ctex.sty (c:/texlive/2025/texmf-dist/tex/latex/l3kernel/expl3.sty (c:/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)) (c:/texlive/2025/texmf-dist/tex/latex/ctex/ctexhook.sty) (c:/texlive/2025/texmf-dist/tex/latex/ctex/ctexpatch.sty) (c:/texlive/2025/texmf-dist/tex/latex/base/fix-cm.sty (c:/texlive/2025/texmf-dist/tex/latex/base/ts1enc.def)) (c:/texlive/2025/texmf-dist/tex/latex/ctex/config/ctexopts.cfg) (c:/texlive/2025/texmf-dist/tex/latex/ctex/engine/ctex-engine-pdftex.def (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/CJKutf8.sty (c:/texlive/2025/texmf-dist/tex/generic/iftex/ifpdf.sty (c:/texlive/2025/texmf-dist/tex/generic/iftex/iftex.sty)) (c:/texlive/2025/texmf-dist/tex/latex/base/inputenc.sty) (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/CJK.sty (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/mule/MULEenc.sty) (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/CJK.enc)) (c:/texlive/2025/texmf-dist/tex/latex/base/fontenc.sty)) (c:/texlive/2025/texmf-dist/tex/latex/cjkpunct/CJKpunct.sty (c:/texlive/2025/texmf-dist/tex/latex/cjkpunct/CJKpunct.spa)) (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/CJKspace.sty) (c:/texlive/2025/texmf-dist/tex/latex/cjk/texinput/UTF8/UTF8.bdg) (c:/texlive/2025/texmf-dist/tex/latex/ctex/ctexspa.def)) (c:/texlive/2025/texmf-dist/tex/latex/zhnumber/zhnumber.sty (c:/texlive/2025/texmf-dist/tex/latex/zhnumber/zhnumber-utf8.cfg)) (c:/texlive/2025/texmf-dist/tex/latex/ctex/scheme/ctex-scheme-chinese.def (c:/texlive/2025/texmf-dist/tex/latex/ctex/config/ctex-name-utf8.cfg)) (c:/texlive/2025/texmf-dist/tex/latex/ctex/fontset/ctex-fontset-fandol.def ! Critical Package ctex Error: CTeX fontset `fandol' is unavailable in current (ctex) mode. Type <return> to continue. ... l.103 } ?
06-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值