cvte技术支持笔试题
20个不定选择,一共90分钟
1 在一个字符串中找到第一个只出现一次的字符。
如输入”abaccdeff”,输出’b’
如果都出现多次,则输出输入次数最多的那个
char FirstNotRepeatChar(string s) {
int size = s.length();
if (size == 0)
return '\0';
const int M = 255; // 表大小,char :1 Byte,0~255
int[] count=new int[M];
for (int i = 0; i < M; i++)
count[i] = 0;
for (int j = 0; j < size; j++)
count[s[j]-'\0']++;
char result;
for (int i = 0; i < size; i++) {
if (count[s[i]-'\0'] == 1) {
result = s[i];
break;
}
}
delete []count;
return result;
}
int main() {
string s = "testonline";
cout << FirstNotRepeatChar(s) << endl;
}
2以单词为单位的逆序排序
输入:hello world
输出: world hello
#include <stdio.h>
#include <string.h>
int main()
{
char s[3000],c[1000][20]={0};//c[j]来储存单词,k是单词中的字母
int i,j=0,k=0;
gets(s);
for(i=0; i<strlen(s); i++)
{
if(s[i]==' ')
{
j++; //遇空格换下一个单词,k归零
k=0;
continue;
}
c[j][k]=s[i];
k++;
}
for(i=j; i>=0; i--)//逆序输出
printf("%s ",c[i]);
}