int main(){
int num[50] = {0};
int i,n,j;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&num[i]);
}
int min_num = num[0];
int max_num = num[0];
for(j=0;j<n;j++){
if(max_num < num[j])
max_num = num[j];
else if(min_num>num[j])
min_num = num[j];
}
int sum = min_num + max_num;
printf("%d\n",sum);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------
*
设计一个字符串过滤程序:从键盘输入小写字母(a--z)组成的字符串,若其中出现重复字符,
将非首次出现的字符过滤掉。如输入:asdfsadsadsa 输出:asdf。
*/
#include <stdio.h>
#include <string.h>
void stringfilter(const char * pinputstr, long linputlen,char * poutputstr){
int i,j,count;
int k=0;
for(i=0;i<strlen(pinputstr);i++){
count = 0;
for(j=0;j<strlen(poutputstr);j++){
if(pinputstr[i] == poutputstr[j]){
count++;
}
}
if(count==0){
poutputstr[k++] = pinputstr[i];
}
}
poutputstr[k] = '\0';
}
int main(){
char buf1[20] = {0};
char buf2[20] = {0};
printf("请输入字符串\n");
scanf("%s",buf1);
stringfilter(buf1,strlen(buf1),buf2);
printf("%s\n",buf2);
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
//10个学生完成考试,老师要划及格线
//要求:(1)及格线是10的倍数
//保证至少有60%的学生及格
//如果所有的学生都高于60分,及格线为60分
#include <stdio.h>
int main(){
int a[10],i,s[7]={0};
for(i=0;i<10;i++){
scanf("%d",&a[i]);
switch(a[i]/10){
case 10: //都高于60分
case 9:
case 8:
case 7:
case 6:s[6]++; break;
case 5:s[5]++; break;
case 4:s[4]++; break;
case 3:s[3]++; break;
case 2:s[2]++; break;
case 1:s[1]++; break;
case 0:s[0]++; break;
}
}
for(i=6;i>0;i--){
if(s[i]>=6) break;
else s[i-1]+=s[i];
}
printf("%d",i*10);
return 0;
}
------------------------------------------------------------------------------------
//去掉最大值,最小值,剩下的数的个数
//sample input: 3,3,5,3,6,9,7,9
//sample output: 3
#include <stdio.h>
#define N 100
int main(){
int a[N],n=0,i,temp,min,max;
char c = '0';
max = 0;
min = 100;
while(c != '\n'){
scanf("%d",&temp);
a[n] = temp;
if(temp>max) max = temp;
if(temp<min) min = temp;
n++;
scanf("%c",&c);
}
temp = 0;
for(i=0;i<n;i++){
if(a[i]<max && a[i]>min) temp++;
}
printf("%d\n",temp);
return 0;
}
--------------------------------------------------------------------------------------
//两个数之差最小,升序输出
//sample input:161 189 167 172 188
//sample output:188 189
#include <stdio.h>
#include <math.h>
int main(){
int a[5],i,j,temp=30,n=-1,m=-1;
for(i=0;i<5;i++){
scanf("%d",&a[i]);
for(j=0;j<i;j++){
if(abs(a[i]-a[j])<temp){
temp = abs(a[i]-a[j]);
if(a[i]>=a[j]){
n = i;
m = j;
}
else{
n = j;
m = i;
}
}
else if(abs(a[i]-a[j]) == temp &&
a[i]>=a[m] && a[i]>=a[n]){
if(a[i]>=a[j]){
n = i;
m = j;
}
else{
n = j;
m = i;
}
}
}
}
printf("%d %d\n",a[m],a[n]);
return 0;
}
-------------------------------------------------------------------------------------------------------------
//输入一串字符串,验证括号是否匹配
//sample input : dfa(sdf)df[dfds(dfd)]
//sample output: 0
#include <stdio.h>
int main(){
char a[100],c;
int i=0;
int flag = 0;
scanf("%c",&c);
while(c!='\n' && flag == 0){
switch(c){
case '(':
case '[': a[i] = c;i++;break;
case ')': if(a[i-1] == '('){
a[i-1] = '\0';
i--;
}
else flag = 1;
break;
case ']': if(a[i-1]=='['){
a[i-1] = '\0';
i--;
}
else flag = 1;
break;
}
scanf("%c",&c);
}
printf("%d\n",flag);
return 0;
}
--------------------------------------------------------------------------------------------------
//判断是否为回文,是的话返回1
#include <stdio.h>
#define N 100
int main(){
int n,m=0,temp;
scanf("%d",&n);
temp = n;
while(temp > 0){
m*=10;
m+=temp%10;
temp = temp/10;
}
if(m==n) printf("1\n");
else printf("0\n");
return 0;
}
-------------------------------------------------------------------------------
//第一行中含有第二行输入数字的数进行排序输出
//sample input 123 423 5645 875 186523
// 23
//sample output 123 423 186523
#include <stdio.h>
#define N 100
int main(){
int a[N],temp,s,i,j;
char c = ' ';
int sort[N],t=0;
i=0;
while(c != '\n'){
scanf("%d%c",&temp,&c);
a[i] = temp;
i++;
}
scanf("%d",&s);
for(j=0;j<=i;j++){
temp = a[j];
while(temp>0){
if(temp % 100 == s){
sort[t] = a[j];
t++;
break;
}
else temp = temp/10;
}
}
for(i=0;i<t-1;i++){
for(j=0;j<t-i-1;j++){
if(sort[j]>sort[j+1]){
temp = sort[j];
sort[j] = sort[j+1];
sort[j+1] = temp;
}
}
}
for(i=0;i<t;i++)
printf("%d ",sort[i]);
printf("\n");
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------------
未完待续》》》》》》》》》》》》》》》》》》》》》》》》》》》》》