PATA1038题解(需复习)
Posted dcklm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PATA1038题解(需复习)相关的知识,希望对你有一定的参考价值。
#include<iostream> #include<vector> #include<algorithm> #include<cstring> using namespace std; struct str{ char s[16]; int index; }; bool cmp(str a,str b) { int len1 = strlen(a.s); int len2 = strlen(b.s); if(len1 == 0 || len2 == 0) return false; int k = 0; while(k < len1 && k < len2) { if(a.s[k] != b.s[k]) { return a.s[k] < b.s[k]; } k++; } if(len1 == len2) return true; int temp = 0; while(k < len1) { if(b.s[temp % len2] != a.s[k]) { return a.s[k] < b.s[temp % len2]; } temp++; k++; } while(k < len2) { if(b.s[k] != a.s[temp % len1]) { return a.s[temp % len1] < b.s[k]; } temp++; k++; } return len1 > len2; } bool test(char * a, char *b) { if(strlen(a) == 0) { if(b[0] == ‘0‘ && strlen(b) == 1) return false; if(b[0] == ‘0‘) { strcpy(a,b+1); }else { strcpy(a,b); } return true; }else { str a_temp, b_temp; strcpy(a_temp.s,a); strcpy(b_temp.s,b); if(a[0] == ‘0‘) { strcpy(a_temp.s,a+1); }if(b[0] == ‘0‘) { strcpy(b_temp.s,b+1); } if(cmp(b_temp,a_temp)) { strcpy(a, b_temp.s); return true; } return false; } } int main() { vector<str>vec, vec_non_zero; int n, _min = 1e9, index; str temp; char ch[16]; ch[0] = ‘