360的笔试题
来源:互联网 发布:淘宝客api教程 编辑:程序博客网 时间:2024/05/21 19:49
当时做的时候没有考虑全面导致,没有ac成功,写代码之间思路一定要清晰,把所有可能的情况都考虑清楚。
#include <stdio.h>#include <string.h>int main(void){ char qizhi[100]; char first[100]; char second[100]; char *ptr; while(scanf("%s",qizhi)&&scanf("%s",first)&&scanf("%s",second)){ int forward=0,backward=0; if(strstr(qizhi,first)){ ptr=strstr(qizhi,first); char *p; if(strstr(ptr,second)) { p=strstr(ptr,second); forward=1; } } strrev(qizhi); if(strstr(qizhi,first)){ ptr=strstr(qizhi,first); char *p; if(strstr(ptr,second)) { p=strstr(ptr,second); backward=1; } } if(forward==1&&backward!=1) printf("forward\n"); else if(backward==1&&forward!=1) printf("backward\n"); else if(backward==1&&forward==1) printf("both\n"); else printf("invalid\n"); } return 0;}
下面是不调用库函数写的:
#include<stdio.h>#include<string.h>int exist(char a[],char b[],char c[]){ int i,j=0,k=0,x1=0,x2=0; for(i=0;a[i]!='\0';i++){ if(a[i]!=b[0]) continue; else{ while(a[i]==b[j]&&b[j]!='\0') { i++; j++; } if(b[j]=='\0') { x1=1; break; }else{ j=0; i=i-1; } } } j=0; for(k=i;a[k]!='\0';k++) { if(a[k]!=c[0]) continue; else{ while(a[k]==c[j]&&c[j]!='\0') { k++; j++; } if(c[j]=='\0') { x2=1; break; }else{ j=0; k=k-1; } }} return x1&&x2;}int main(){ char qizhi[100]; char first[100]; char second[100]; while(scanf("%s",qizhi)&&scanf("%s",first)&&scanf("%s",second)){ int x1,x2; x1=exist(qizhi,first,second); char *ret1 = strrev(qizhi);//字符串逆序 x2=exist(ret1,first,second); if(x1==1&&x2!=1) printf("forward\n"); else if(x2==1&&x1!=1) printf("backward\n"); else if(x1==1&&x2==1) printf("both\n"); else printf("invalid\n"); } return 0;}
不使用库函数的时候,中间的变量移动一定要搞清楚
0 0
- 360的笔试题
- 笔试题:360找镇长的题。
- 360 笔试题 因子计算器的实现
- synplify的笔试题
- ST的笔试题
- 摩托罗拉的笔试题
- CA的笔试题
- 江苏电信的笔试题
- 华为的笔试题
- 海信的笔试题
- 某公司的笔试题
- 好玩的笔试题
- 金山的笔试题
- sizeof的笔试题
- 集合的笔试题
- 我的笔试题
- 好玩的笔试题
- 百度的笔试题
- HDU 1175 连连看
- ZZULIOJ 1108: 打印数字图形(函数专题,水题)
- Opencv实现:SIFT特征提取+RANSAC剔除误匹配点
- MySQL登录出现 ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- iOS 个别问题
- 360的笔试题
- play框架2.5.6教程——使用play控制台
- 【bzoj 1492】【codevs 1797】 [NOI2007]货币兑换Cash (dp+cdq分治)
- ListView的使用及优化
- LeetCode学习篇二——分治法
- KVO 和 NSNotification
- ubuntu 安装QT
- poj2762 Going from u to v or from v to u?--trajan算法 & 强连通分量 & 缩点 & 拓扑排序
- ListView和ExpandableListView的侧滑删除操作