2016 360校招笔试编程题
来源:互联网 发布:淘宝怎么改评价用手机 编辑:程序博客网 时间:2024/06/05 00:31
360校招编程题
第一题
题目
有一个小镇选举镇长,满足条件如下:
1. 每个人都认识自己;
2. 镇长必须不认识除了自己以外的任何人;
3. 每个人都必须认识镇长。
输入:
- 第一行为数据个数n,表示之后将有n组样本;
- 接下来就是第一组数据,m:镇上的人数,k:下面将要写的人际关系;
- 接下来就是人际关系,“q p”:第q个人认识第p个人(并不能表示p认识q);
输出:
- 该镇镇长候选人的个数,单独一行;
- 每个候选人,分别用空格分开。
i.e.
输入
3
2 0
3 2
2 1
3 1
4 5
1 1
2 1
3 1
4 1
3 2输出
01
1
1
1
C语言代码
#include <stdio.h>#include <stdlib.h>typedef struct people_s{ unsigned int beKnown; unsigned int knowWho;}people_t;void chooseCaptain();int main(){ int count = 0; scanf("%d",&count); while(count--) chooseCaptain(); return 0;}void chooseCaptain(){ unsigned int numberOfPeople = 0; unsigned int numberOfRelationship = 0; unsigned int *captain; unsigned int numberOfCaptain = 0; int i = 0,pIndex = 0; scanf("%d%d",&numberOfPeople,&numberOfRelationship); captain = (unsigned int *)calloc(numberOfPeople,sizeof(unsigned int)); people_t *people = (people_t *)calloc(numberOfPeople,sizeof(people_t)); for(i=0,pIndex=0;i<numberOfRelationship;++i){ scanf("%d",&pIndex); int tmp; scanf("%d",&tmp); if(tmp == pIndex) continue; else{ ++people[pIndex-1].knowWho; ++people[tmp-1].beKnown; } } //find the person for(i=0;i<numberOfPeople;++i){ //printf("%d %d %d\n",i,people[i].beKnown,people[i].knowWho); if(people[i].beKnown == numberOfPeople-1 && people[i].knowWho == 0) captain[numberOfCaptain++] = i+1; } //print printf("%d\n",numberOfCaptain); for(i=0;i<numberOfCaptain;++i) printf("%d ",captain[i]); printf("\n");}
第二题
题目
找出一个字符串中只出现一次的字符,且是第一个出现。
输入:
- n:一共有n组数据;
- 一行一个字符串。
i.e.
输入
2
asdssabass
helloworld输出
d
h
C++代码
#include <iostream>#include <map>#include <string.h>using namespace std;class Solution{ public: char firstSingleChar(string str); private: map<char,int> dict;};char Solution::firstSingleChar(string str){ dict.clear(); for(int i=0;i<str.length();++i){ if(dict[str[i]] == -1) continue; else if(dict[str[i]] == 0) dict[str[i]] = i; else dict[str[i]] = -1; } char minChar = 0; int minIndex = 0x7fffffff; for(map<char,int>::const_iterator beg = dict.begin(); beg != dict.end(); ++beg){ if(beg->second == -1) continue; else if(beg->second < minIndex){ minIndex = beg->second; minChar = beg->first; } } return minChar;}int main(){ Solution s; int count = 0; cin>>count; string str = ""; while(count--){ cin>>str; cout<<s.firstSingleChar(str)<<endl; } return 0;}
0 0
- 2016 360校招笔试编程题
- 2017校招 360 笔试题 编程题 内存管理
- 2016年360校招笔试题
- 京东2015校招笔试编程题
- 阿里2018校招笔试编程题
- 腾讯2016秋招笔试编程题
- 2016CVTE春招笔试编程题
- 360校招笔试题
- 校招笔试题
- 360 2016校招笔试-读代码题
- (2016)京东笔试校招编程题目
- 2017年网易校招笔试编程题第二题
- 2017年网易校招笔试编程题第一题
- 360校招笔试算法题
- 2015年360校招笔试题
- 迅雷2014校招笔试题之多线程编程
- 2014 微软校招笔试答案 编程题
- 迅雷2014校招笔试题之多线程编程
- 黑马程序员——C语言笔记之预处理指令和模块化编程
- 浅谈Android列表ListView下拉刷新控件的实现(一)
- angular.fromJson方法与toJson方法
- Constructing Roads
- Gray code(hdu5375+异或二进制的规律)
- 2016 360校招笔试编程题
- WSTMall V1.2.1_150810程序发布
- 黑马程序员——Java基础---继承,抽象,多态,接口,包,内部类
- Android 程序crash后重新启动
- 实现自定义对话框中的属性动画-续
- IOS Q&A __weak typeof(self) weakSelf = self 是什么意思?
- hdu 1686 Oulipo
- 人民币创出20年来最大单日跌幅,中国股市振荡
- IOS九宫格