2 条题解
-
1
using namespace std; struct data { char number[101]; int rank; void operator=(data& a) { strcpy(this->number,a.number); this->rank=a.rank; } }a[21]; struct my_str { int num; void output() { cout<<this->num; } void compare(my_str other) { if(this->num<other.num) cout<<"Smaller"; else if(this->num==other.num) cout<<"Same"; else cout<<"Bigger"; } }; #define LEFT_IS_BIGGER false #define RIGHT_IS_BIGGER true bool WHO_IS_BIGGER(char* a,char* b) { int lena=strlen(a); int lenb=strlen(b); if(lena!=lenb) { if(lena>lenb) return LEFT_IS_BIGGER; else return RIGHT_IS_BIGGER; } else { for(int i=0;i<lena;i++) { if(a[i]>b[i]) return LEFT_IS_BIGGER; else if(a[i]<b[i]) return RIGHT_IS_BIGGER; else continue; } } } void my_swap(data& a,data& b) { data temp=a; a=b; b=temp; } int main() { int n; cin>>n; for(int i=0;i<n;i++) { scanf("%s",a[i].number); a[i].rank=i+1; } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(WHO_IS_BIGGER(a[i].number,a[j].number)==RIGHT_IS_BIGGER) { my_swap(a[i],a[j]); } } } cout<<a[0].rank<<endl; printf("%s",a[0].number); }
样例有点水,能过刁钻的数据
-
1
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; int n; struct node{ string s; int nu; }arr[25]; bool cmp(node n1,node n2){ if(n1.s.length()!=n2.s.length()) return n1.s.length()>n2.s.length(); else return n1.s>n2.s; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ cin >> arr[i].s; arr[i].nu = i; } sort(arr+1,arr+1+n,cmp); cout << arr[1].nu << endl << arr[1].s; return 0; }
- 1
信息
- ID
- 750
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 2
- 标签
- 递交数
- 14
- 已通过
- 7
- 上传者