https://www.nowcoder.com/pat/2/problem/281
吐槽:说实话,这道题太坑了,如果只是简单的判断三角形,估计大家都会做,就是最长边小于其他两边之和。但是这道题数据超级大,所以还要用到大数加法。另外一点,不知道牛客网是什么编译器,我在DEVC++上都能编译通过,他就是要报错,主要是就是有段bool代码,我原来写的是:
if(lena != lenb) return lena > lenb;
else if(lena == lenb) return strcmp(a.str,b.str) > 0;
死活不给我过,还要报编译错误,真是日了整个动物园了。
我改了一丢丢,其实毫无意义,但是竟然能过,excuse me?
if(lena > lenb) return lena > lenb;
else if(lena == lenb) return strcmp(a.str,b.str) > 0;
else return lena > lenb;
说实话,我看不到丝毫区别!
搞了大半夜,真的畜生!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct E{
char str[105];
}edge[3];
bool cmp(E &a,E &b){
int lena = strlen(a.str);
int lenb = strlen(b.str);
if(lena > lenb) return lena > lenb;
else if(lena == lenb) return strcmp(a.str,b.str) > 0;
else return lena > lenb;
}
int main(){
while(scanf("%s%s%s",edge[0].str,edge[1].str,edge[2].str)!=EOF){
sort(edge,edge+3,cmp);
printf("%s\n",edge[0].str);
printf("%s\n",edge[1].str);
printf("%s\n",edge[2].str);
char *s1=edge[1].str,*s2=edge[2].str;
int sum[105];
int len1 = strlen(s1);
int len2 = strlen(s2);
int c=0,tmp,i;
for(i=0;i < len2 && i<len1;i++){
tmp = c + s1[len1-1-i]+s2[len2-1-i]-'0'-'0';
c = tmp / 10;
sum[i]=tmp%10;
}
while(i<len1){
tmp = c + s1[len1-1-i] - '0';
c = tmp / 10;
sum[i++]=tmp%10;
}
while(i<len2){
tmp = c + s2[len2-1-i] - '0';
c = tmp / 10;
sum[i++]=tmp%10;
}
if(c!=0) sum[i++]=c;
char ss[105];
int j;
for(j=0;j<i;j++){
ss[j]=sum[i-1-j]+'0';
}
ss[j]='\0';
int len0 = strlen(edge[0].str);
int lens = strlen(ss);
//printf("%s\n",ss);
if(len0 < lens) printf("Yes\n");
else if(len0 == lens && strcmp(edge[0].str,ss) < 0) printf("Yes\n");
else printf("No\n");
}
return 0;
}