{"id":627,"date":"2013-09-15T10:14:45","date_gmt":"2013-09-15T02:14:45","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=627"},"modified":"2013-09-15T10:14:45","modified_gmt":"2013-09-15T02:14:45","slug":"%e4%b9%9d%e5%ba%a6oj-%e9%a2%98%e7%9b%ae1190%ef%bc%9a%e5%a4%a7%e6%95%b4%e6%95%b0%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=627","title":{"rendered":"\u4e5d\u5ea6OJ \u9898\u76ee1190\uff1a\u5927\u6574\u6570\u6392\u5e8f"},"content":{"rendered":"<dl>\n<dt><b>\u9898\u76ee\u63cf\u8ff0\uff1a<\/b><\/dt>\n<dd>\u5bf9N\u4e2a\u957f\u5ea6\u6700\u957f\u53ef\u8fbe\u52301000\u7684\u6570\u8fdb\u884c\u6392\u5e8f\u3002\n<\/dd>\n<\/dl>\n<dl>\n<dt><b>\u8f93\u5165\uff1a<\/b><\/dt>\n<dd>\u8f93\u5165\u7b2c\u4e00\u884c\u4e3a\u4e00\u4e2a\u6574\u6570N\uff0c(1&lt;=N&lt;=100)\u3002<br \/>\n\u63a5\u4e0b\u6765\u7684N\u884c\u6bcf\u884c\u6709\u4e00\u4e2a\u6570\uff0c\u6570\u7684\u957f\u5ea6\u8303\u56f4\u4e3a1&lt;=len&lt;=1000\u3002<br \/>\n\u6bcf\u4e2a\u6570\u90fd\u662f\u4e00\u4e2a\u6b63\u6570\uff0c\u5e76\u4e14\u4fdd\u8bc1\u4e0d\u5305\u542b\u524d\u7f00\u96f6\u3002\n<\/dd>\n<\/dl>\n<dl>\n<dt><b>\u8f93\u51fa\uff1a<\/b><\/dt>\n<dd>\u53ef\u80fd\u6709\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\uff0c\u5bf9\u4e8e\u6bcf\u7ec4\u6570\u636e\uff0c\u5c06\u7ed9\u51fa\u7684N\u4e2a\u6570\u4ece\u5c0f\u5230\u5927\u8fdb\u884c\u6392\u5e8f\uff0c\u8f93\u51fa\u6392\u5e8f\u540e\u7684\u7ed3\u679c\uff0c\u6bcf\u4e2a\u6570\u5360\u4e00\u884c\u3002\n<\/dd>\n<\/dl>\n<dl>\n<dt><b>\u6837\u4f8b\u8f93\u5165\uff1a<\/b><\/dt>\n<dd>\n<pre>3\n11111111111111111111111111111\n2222222222222222222222222222222222\n33333333<\/pre>\n<\/dd>\n<\/dl>\n<dl>\n<dt><b>\u6837\u4f8b\u8f93\u51fa\uff1a<\/b><\/dt>\n<dd>\n<pre>33333333\n11111111111111111111111111111\n2222222222222222222222222222222222<\/pre>\n<\/dd>\n<\/dl>\n<p>==========================================<br \/>\n<code lang=\"c++\"><br \/>\n#include <iostream><br \/>\n#include <string.h><br \/>\n#include <stdlib.h><br \/>\nusing namespace std;<br \/>\nstruct BigInt<br \/>\n{<br \/>\n    char data[1001]; \/\/ \u9ad8\u4f4d\u5728\u524d\uff0c\u4f4e\u4f4d\u5728\u540e<br \/>\n};<br \/>\nint compare(const void *pA, const void *pB)<br \/>\n{<br \/>\n    BigInt *a = (BigInt *)pA;<br \/>\n    BigInt *b = (BigInt *)pB;<br \/>\n    int len_a = strlen(a->data);<br \/>\n    int len_b = strlen(b->data);<br \/>\n    if(len_a < len_b)\n        return -1;\n    else if(len_a > len_b)<br \/>\n        return 1;<br \/>\n    else<br \/>\n    {<br \/>\n        int i;<br \/>\n        for(i = 0; i<len_a; i++)\n        {\n            if(a->data[i] != b->data[i])<br \/>\n                return a->data[i] - b->data[i];<br \/>\n        }<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    char input[1001];<br \/>\n    int N;<br \/>\n    while(cin >> N)<br \/>\n    {<br \/>\n        BigInt *bigInts = new BigInt[N];<br \/>\n        int i;<br \/>\n        for(i=0; i<n; i++)\n        {\n            cin >> input;<br \/>\n            strcpy(bigInts[i].data, input);<br \/>\n        }<br \/>\n        qsort(bigInts, N, sizeof(BigInt), compare);<br \/>\n        for(i=0; i<n; i++)\n        {\n            cout << bigInts[i].data << endl;\n        }\n        delete []bigInts;\n    }\n    return 0;\n}\n\/**************************************************************\n    Problem: 1190\n    User: iorange\n    Language: C++\n    Result: Accepted\n    Time:30 ms\n    Memory:1520 kb\n****************************************************************\/\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0\uff1a \u5bf9N\u4e2a\u957f\u5ea6\u6700\u957f\u53ef\u8fbe\u52301000\u7684\u6570\u8fdb\u884c\u6392\u5e8f\u3002 \u8f93\u5165\uff1a \u8f93\u5165\u7b2c\u4e00\u884c\u4e3a\u4e00\u4e2a\u6574\u6570N\uff0c(1&lt;=N&lt;=100)\u3002 \u63a5\u4e0b\u6765\u7684N\u884c\u6bcf\u884c\u6709\u4e00\u4e2a\u6570\uff0c\u6570\u7684\u957f\u5ea6\u8303\u56f4\u4e3a1&lt;=len&lt;=1000\u3002 \u6bcf\u4e2a\u6570\u90fd\u662f\u4e00\u4e2a\u6b63\u6570\uff0c\u5e76\u4e14\u4fdd\u8bc1\u4e0d\u5305\u542b\u524d\u7f00\u96f6\u3002 \u8f93\u51fa\uff1a \u53ef\u80fd\u6709\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\uff0c\u5bf9\u4e8e\u6bcf\u7ec4\u6570\u636e\uff0c\u5c06\u7ed9\u51fa\u7684N\u4e2a\u6570\u4ece\u5c0f\u5230\u5927\u8fdb\u884c\u6392\u5e8f\uff0c\u8f93\u51fa\u6392\u5e8f\u540e\u7684\u7ed3\u679c\uff0c\u6bcf\u4e2a\u6570\u5360\u4e00\u884c\u3002 \u6837\u4f8b\u8f93\u5165\uff1a 3 11111111111111111111111111111 2222222222222222222222222222222222 33333333 \u6837\u4f8b\u8f93\u51fa\uff1a 33333333 11111111111111111111111111111 2222222222222222222222222222222222 ========================================== #include #include #include using namespace std; struct BigInt { char data[1001]; \/\/ \u9ad8\u4f4d\u5728\u524d\uff0c\u4f4e\u4f4d\u5728\u540e }; int compare(const void *pA, const void *pB) { BigInt *a = (BigInt *)pA; BigInt *b = (BigInt *)pB; int len_a = strlen(a->data); int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[132],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-study","tag-oj"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=627"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}