#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define maxn 10000
struct PART{
string S;
int N,Nsum;
};
vector<PART> V;
vector<int> prime;
bool v[maxn+5];
//-----------------------------------------
int Prime(int x){
int sum=0, k=0, p;
while(k<=maxn && x>1){
if(x%prime[k]==0) {
if(prime[k]!=p) sum += prime[k];
p=prime[k];
x /= prime[k];
}
else k++;
}
if(x>1 && x!=p) sum += x;
return sum;
}
//-----------------------------------------
bool comp1(PART a, PART b){
if(a.Nsum>b.Nsum) return true;
else if(a.Nsum==b.Nsum && a.S<b.S) return true;
else if(a.Nsum==b.Nsum && a.S==b.S && a.N>b.N) return true;
else return false;
}
//=========================================
int main() {
char tmp[200];
int n,ns;
memset(v,0,sizeof(v));
for(int i=2; i<maxn; i++){
if(v[i]==0){
v[i]=1;
prime.push_back(i);
int j=i+i;
while(j<maxn) { v[j]=1; j+=i; }
}
}
while(scanf("%s",tmp)!=-1){
int x=0, ps;
for(int i=0; i<strlen(tmp); i++){
if(tmp[i]>='0' && tmp[i]<='9')
x = x*10 + (tmp[i]-'0');
}
ps=Prime(x);
//printf("@@@ %s %d %d\n",tmp,x,ps);
V.push_back({tmp,x,ps});
}
sort(V.begin(), V.end(), comp1);
for(int i=0; i<V.size(); i++) cout<<V[i].S<<"\n";
}
text 遞增
還是過不了!
您的答案為: m37yvd0ORRXl2o 正確答案為: dNlP6743HujSnV
--------------------------------------------
實際的測試結果是: (應該沒錯啊)
dNlP6743HujSnV
m37yvd0ORRXl2o
--------------------------------------------------------------------
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define maxn 10000
struct PART{
string S,Sx;
int N,Nsum;
};
vector<PART> V;
vector<int> prime;
bool v[maxn+5];
//-----------------------------------------
int Prime(int x){
int sum=0, k=0, p;
while(k<=maxn && x>1){
if(x%prime[k]==0) {
if(prime[k]!=p) sum += prime[k];
p=prime[k];
x /= prime[k];
}
else k++;
}
if(x>1 && x!=p) sum += x;
return sum;
}
//-----------------------------------------
bool comp1(PART a, PART b){
if(a.Nsum>b.Nsum) return true;
else if(a.Nsum==b.Nsum && a.Sx<b.Sx) return true;
else if(a.Nsum==b.Nsum && a.S==b.S && a.N>b.N) return true;
else return false;
}
//=========================================
int main() {
char tmp[200];
int n,ns;
memset(v,0,sizeof(v));
for(int i=2; i<maxn; i++){//建立質數表
if(v[i]==0){
v[i]=1;
prime.push_back(i);
int j=i+i;
while(j<maxn) { v[j]=1; j+=i; }
}
}
while(scanf("%s",tmp)!=-1){
char ss[1000];
int x=0, ps, k=0;
for(int i=0; i<strlen(tmp); i++){
if(tmp[i]>='0' && tmp[i]<='9')
x = x*10 + (tmp[i]-'0');
else
ss[k++] = tmp[i];
}
ss[k] = '\0';
ps=Prime(x);
//printf("%s %s %d %d\n",tmp,ss,x,ps);
V.push_back({tmp,ss,x,ps});
}
sort(V.begin(), V.end(), comp1);
for(int i=0; i<V.size(); i++) cout<<V[i].S<<"\n";
}