1.
通過鍵盤輸入一串小寫字母(a~z)組成的字串。請編寫乙個字串過濾程式,若字串中出現多個相同的字元,將非首次出現的字元過濾掉。
比如字串「abacacde」過濾結果為「abcde」。
要求實現函式:void stringfilter(const char *pinputstr, long linputlen, char *poutputstr);
【輸入】 pinputstr: 輸入字串
linputlen: 輸入字串長度
【輸出】 poutputstr: 輸出字串,空間已經開闢好,與輸入字串等長;
【注意】只需要完成該函式功能演算法,中間不需要有任何io的輸入輸出
示例 輸入:「deefd」 輸出:「def」
輸入:「afafafaf」 輸出:「af」
輸入:「pppppppp」 輸出:「p」
main函式已經隱藏,這裡保留給使用者的測試入口,在這裡測試你的實現函式,可以呼叫printf列印輸出
當前你可以使用其他方法測試,只要保證最終程式能正確執行即可,該函式實現可以任意修改,但是不要改變函式原型。
一定要保證編譯執行不受影響
[cpp]view plain
copy
print?
//華為第一題 19:19-19:36 17分鐘
#include
#include
using
namespace std;
bool g_flag[26];
void stringfilter(const
char *pinputstr, long linputlen, char *poutputstr)
const
char *p = pinputstr;
while(*p != '\0')
else
}
poutputstr[i] = '\0';
}
int main()
//華為第一題 19:19-19:36 17分鐘
#include #include using namespace std;
bool g_flag[26];
void stringfilter(const char *pinputstr, long linputlen, char *poutputstr)
const char *p = pinputstr;
while(*p != '\0')
else
} poutputstr[i] = '\0';
} int main()
if (num > 1)
num = 1;
for (int j = size; j > 0; j--)
i +=size;
poutputstr[i++] = *(p-1);
p++;
}else
}
poutputstr[i] = '\0';
}
int main()
//華為第二題 19:40 - 20:10 中間耽誤3分鐘
#include #include using namespace std;
void stringzip(const char *pinputstr, long linputlen, char *poutputstr)
if (num > 1)
num = 1;
for (int j = size; j > 0; j--)
i +=size;
poutputstr[i++] = *(p-1);
p++;
}else
} poutputstr[i] = '\0';
}
int main()
input++;
operator1 = sum;
sum = 0;
while(*input != ' ')
input++;
*temp = '\0';
if (strlen(ope) > 1 )
while(*input != '\0') //獲得運算元2
operator2 = sum;
sum = 0;
switch (*ope)
}
int main()
//華為第三題 20:29 - 20:40
#include using namespace std;
void arithmetic(const char *pinputstr, long linputlen, char *poutputstr)
input++;
operator1 = sum;
sum = 0;
while(*input != ' ')
input++;
*temp = '\0';
if (strlen(ope) > 1 )
while(*input != '\0') //獲得運算元2
operator2 = sum;
sum = 0;
switch (*ope)
} int main()
;
gets(str); //要點1:動態的輸入1--50個整數,不能確定個數,只能用字串輸入,然後分離出來
int i=0;
int j=0;
int sign=1;
while(str[i]!='\0')
else
if(str[i]!='\0') //不用else的話,負號也會減去『0』
}
i++;
if(str[i]==',' || str[i]=='\0') //這個判斷是在i自加以後
}
sort(a,j);
printf("max number + min number = %d",a[0]+a[j-1]);
return 0;
}
void sort(int a,int n) //選擇排序
if(i!=k)
}
for(i=0;iprintf("%-5d",a[i]);
puts("");
}
人人網2014筆試演算法題彙總
1.給出乙個有序陣列啊,長度為len,另外給出第三個數x,問是否能在陣列中找到兩個數,這兩個數之和等於第三個數x。我們首先看到第一句話,這個陣列是有序的,所以,我們可以定義兩個指標,乙個指向陣列的第乙個元素,另乙個指向應該指向的位置 這個需要看具體的實現和陣列給定的值 首先計算兩個位置的和是否等於給...
暴風影音2014筆試演算法題彙總
1.自定義實現字串轉為整數的演算法,例如把 123456 轉成整數123456.輸入中可能存在符號,和數字 返回結果的有效標誌 enum status int gstatus valid int strtoint const char str while digit 0 digit 非法輸入 els...
華為2014 演算法彙總
1.通過鍵盤輸入一串小寫字母 a z 組成的字串。請編寫乙個字串過濾程式,若字串中出現多個相同的字元,將非首次出現的字元過濾掉。比如字串 abacacde 過濾結果為 abcde 要求實現函式 void stringfilter const char pinputstr,long linputlen...