问题 J: 例题6-9 字符串求最大值:http://codeup.cn/contest.php?cid=100000569
这次犯的错误,把负数以为是false:
- C 语言把任何非零和非空的值假定为 true,把零或 null 假定为 false。
if(-1){
printf("1");
}//这条语句是可以输出的这题答案:
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
char a[3][20];
char max[20];
for(int i=0;i<3;i++){
gets(a[i]);
}
if(strcmp(a[0],a[1])){
strcpy(max,a[0]);
}else{
strcpy(max,a[1]);
}
if(strcmp(a[2],max)>0){
strcpy(max,a[2]);
}
puts(max);
return 0;
}

京公网安备 11010502036488号