某虎公司的笔试
来源:互联网 发布:linux磁盘空间扩容 编辑:程序博客网 时间:2024/06/09 16:59
笔试有两个编程题,第一个是输出每个数字的质因数,并用5*3的像素打印出来;第二个是判断输入数据的类别。第二个相对容易一些,第一个当时没写完,题目如下:
输入:
24
输出:
- | -| - - - | | - * -| | - -
当时想到用队列处理,把质因数获取之后,输出形式没来得及做,回去之后又完善了下,代码如下:
#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); enqueue(&head,&tail,0); } printNum(head); //printQueue(head);return 0;}void printNum(resPtr head){ resPtr now = head; if(head == NULL) printf("The Queue is empty!\n\n"); else{ while(head != NULL){ now = head; while(1){ if(now->data == '*' && now->next->data == '*') break; else switch(now->data){ case '1': case '4': printf(" "); break; case '2': case '3': case '5': case '6': case '7': case '8': case '9': printf(" - "); break; case '*': printf(" "); break; } now = now->next; } printf("\n"); now = head; while(1){ if(now->data == '*' && now->next->data == '*') break; else switch(now->data){ case '1': case '2': case '3': case '7': printf(" |"); break; case '4': case '8': case '9': printf("| |"); break; case '5': case '6': printf("| "); break; case '*': printf(" "); break; } now = now->next; } printf("\n"); now = head; while(1){ if(now->data == '*' && now->next->data == '*') break; else switch(now->data){ case '1': case '7': printf(" "); break; case '2': case '3': case '4': case '5': case '6': case '8': case '9': printf(" - "); break; case '*': printf("*"); break; } now = now->next; } printf("\n"); now = head; while(1){ if(now->data == '*' && now->next->data == '*') break; else switch(now->data){ case '1': case '3': case '4': case '5': case '7': case '9': printf(" |"); break; case '2': printf("| "); break; case '6': case '8': printf("| |"); break; case '*': printf(" "); break; } now = now->next; } printf("\n"); now = head; while(1){ if(now->data == '*' && now->next->data == '*') break; else switch(now->data){ case '1': case '4': case '7': printf(" "); break; case '2': case '3': case '5': case '6': case '8': case '9': printf(" - "); break; case '*': printf(" "); break; } now = now->next; } printf("\n"); //while * 5 now = now->next; head = now->next; } } }void addqueue(resPtr *head, resPtr *tail, int n){ if(n < 10){ enqueue(head,tail,n); } else{ if(n > 10) addqueue(head,tail,n/10); enqueue(head,tail,n % 10); }}void enqueue(resPtr *head, resPtr *tail, int value){ resPtr newPtr; newPtr = malloc(sizeof(struct Result)); if(newPtr != NULL){ if(value == 0) newPtr->data = '*'; else newPtr->data = '0'+value; newPtr->next = NULL; if(*head == NULL) *head = newPtr; else (*tail)->next = newPtr; *tail = newPtr; } else printf("No memory :( \n");}void printQueue(resPtr head){ if(head == NULL) printf("The Queue is empty!\n\n"); else{ while(head != NULL){ printf("%4c",head->data); head = head->next; } }}
按部就班的写,没有用什么巧妙的办法
0 0
- 某虎公司的笔试
- 某游戏公司的部分笔试题
- 一些公司的笔试题
- 一些公司的笔试题
- Trilogy公司的笔试题
- Trilogy公司的笔试题
- 记爱立信公司的笔试
- 第三家公司的笔试
- xx公司的笔试有感
- 某游戏公司笔试题
- 某国际知名IT公司笔试
- 某知名公司笔试题目
- 某知名公司笔试题目
- 某知名公司笔试题目
- 某国际知名IT公司笔试
- 某H公司笔试知识点
- 某著名公司的一道JAVA笔试题
- 某知名IT公司最近的一道笔试编程题
- 性能优化之Traceview工具的使用
- java学习之JDK5新特性
- AFNetworking从指定网址下载文件的两种方式总结 - 家柱
- yum whatprovides 通过模块找包
- Dave APP GLOBAL_CCU4_TEST on HW Signal Connection
- 某虎公司的笔试
- 简易计算器NetBeans Ide
- .NET基础--数组
- Android:动画系统
- ASP.NET MVC中的统一化自定义异常处理
- iOS线程休眠及取消
- 5.Longest Palindromic Substring
- 第三周的顺序表的基本运算
- linux网络编程之tcp模板