笔试有两个编程题,第一个是输出每个数字的质因数,并用5*3的像素打印出来;第二个是判断输入数据的类别。第二个相对容易一些,第一个当时没写完,题目如下:
输入:
2
4
输出:
-
|
-
|
-
- -
| |
- * -
| |
- -
当时想到用队列处理,把质因数获取之后,输出形式没来得及做,回去之后又完善了下,代码如下:
#include <stdio.h>
#include <stdlib.h>
struct Result{
char data;
struct Result *next;
};
typedef struct Result * resPtr;
void enqueue(resPtr *head, resPtr *tail, int value);
void printQueue(resPtr head);
void addqueue(resPtr *head, resPtr *tail, int n);
void printNum(resPtr head);
int main(int argc, char **argv)
{
int n,i;
char c;
resPtr head = NULL;
resPtr tail = NULL;
while(1){
scanf("%d",&n);
if(n < 1)
break;
for (i = 2; i *i <= n;)
{
if (n % i == 0)
{
addqueue(&head,&tail,i);
enqueue(&head,&tail,0);
n /= i;
}
else
i++;
}
addqueue(&head,&tail,n);
enqueue(&head,&tail,0);