走投无路了
c吧
全部回复
仅看楼主
level 8
小小绿树 楼主
题目和代码如图,题主是想像样例那样不要求输入n值也能确定矩阵大小,中途也问过好几次AI了,但得到的答案都不理想。图示代码也没法正常运行,照样例输入完以后程序没有执行而是继续等待输入数据。麻烦各位大佬查查bug,不胜感激!
2025年10月13日 12点10分 1
level 1
还要吗,还要给你
#include<stdio.h>
#include<conio.h>
#define MAX_INPUT 100
int main(){
int matrix[MAX_INPUT] = {};
int i=0;
int n=0;
int ch;
printf("Press Enter Change Line,Press Q End\n");
while (i < MAX_INPUT){
ch = _getch();
if (ch > 47 && ch <58) {
printf("%c ",ch);
matrix[i] = ch-48;
i++;
continue;
} else
if (ch == 13) printf("\n");
else
if (ch =='Q') break;
}
int size = i;
for(int i=0;i*i <= MAX_INPUT;i++){
if (size == i*i){
n=i;
break;
}
}
printf("\n");
if (n==0) printf ("this isn't rect,plesase restart this program"); else printf("this is rect");
printf("\n size: %d,n: %d\n",size,n);
int rect[n][n];
int new_rect[n][n];
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
rect[x][y] = matrix[x+y*n];
}
}
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
new_rect[x][y] = rect[(y)][((n-1)-x)];
}
}
printf("new rect:\n");
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
printf("%d ",new_rect[x][y]);
}
printf("\n");
}
_getch();
}
2025年10月14日 13点10分 0
感谢^ω^,我仔细研读一下
2025年10月14日 13点10分
level 1
。。。手机好像不能用回车,没法换行,你把那个13改成随便什么其它字符吧
2025年10月14日 13点10分 4
level 1
我!保证!这个!可以运行!!
#include<stdio.h>
#include<conio.h>
#define MAX_INPUT 100
int main(){
int matrix[MAX_INPUT] = {};
int i=0;
int n=0;
int ch;
printf("Press w to next Line,Press q End\n");
while (i < MAX_INPUT){
ch = _getch();
if (ch > 47 && ch <58) {
printf("%c ",ch);
matrix[i] = ch-48;
i++;
continue;
} else
if (ch =='w') printf("\n");
else
if (ch =='q') break;
}
int size = i;
for(int i=0;i*i <= MAX_INPUT;i++){
if (size == i*i){
n=i;
break;
}
}
printf("\n");
if (n==0) printf ("this isn't rect,plesase restart this program"); else printf("this is rect");
printf("\n size: %d,n: %d\n",size,n);
int rect[n][n];
int new_rect[n][n];
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
rect[x][y] = matrix[x+y*n];
}
}
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
new_rect[x][y] = rect[(y)][((n-1)-x)];
}
}
printf("new rect:\n");
for(int y=0;y < n;y++){
for(int x=0;x < n;x++){
printf("%d ",new_rect[x][y]);
}
printf("\n");
}
_getch();
}
2025年10月14日 13点10分 5
level 1
我试了下你的这个编译器,已经可以保证在你的环境下可以运行了
2025年10月14日 13点10分 6
level 1
按w换行,按q结束输出
2025年10月14日 13点10分 7
1