]]>poj1503--澶ф暣鏁板姞娉?/title>http://www.shnenglu.com/hoolee/archive/2012/08/11/186882.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Sat, 11 Aug 2012 00:58:00 GMThttp://www.shnenglu.com/hoolee/archive/2012/08/11/186882.htmlhttp://www.shnenglu.com/hoolee/comments/186882.htmlhttp://www.shnenglu.com/hoolee/archive/2012/08/11/186882.html#Feedback0http://www.shnenglu.com/hoolee/comments/commentRss/186882.htmlhttp://www.shnenglu.com/hoolee/services/trackbacks/186882.html浠ヤ笅鏄湰棰樹唬鐮侊細
#include<stdio.h> #include<stdlib.h> #include<string.h> #define LEN 200 int Max(int a, int b) { if(a > b) return a; return b; } void Add(char*num1, char*num2) {
int len1, len2; int i, j; i = LEN -1; while(num1[--i] ==0&& i >0); len1 = i; len2 = strlen(num2); int lenm = Max(len1, len2); for(i =0; i < len2; i++) num2[i] -='0'; for(i =0; i < len2 /2; i++)//reverse num2 { int c = num2[i]; num2[i] = num2[len2 -1- i]; num2[len2 -1- i] = c; } for(i =0; i < lenm +2; i++)//add num1 && num2 num1[i] += num2[i]; int t =0; int t2; for(i =0; i < lenm +2; i++)//carry bit { t2 = num1[i] + t; num1[i] = t2 %10; t = t2 /10; } } int main() { int i, j; char num1[LEN]; char num2[LEN]; memset(num1, 0, sizeof(num1)); memset(num2, 0, sizeof(num2)); gets(num2); while(strcmp(num2, "0") !=0) { Add(num1, num2); memset(num2, 0, sizeof(num2)); gets(num2); } i = LEN -1; while(num1[--i] ==0&& i >0); if(i ==0) printf("0\n"); else { for(; i >=0; i--) printf("%d", num1[i]); putchar(10); } //system("pause"); }
]]>zoj1201http://www.shnenglu.com/hoolee/archive/2012/08/02/186041.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Thu, 02 Aug 2012 08:19:00 GMThttp://www.shnenglu.com/hoolee/archive/2012/08/02/186041.htmlhttp://www.shnenglu.com/hoolee/comments/186041.htmlhttp://www.shnenglu.com/hoolee/archive/2012/08/02/186041.html#Feedback0http://www.shnenglu.com/hoolee/comments/commentRss/186041.htmlhttp://www.shnenglu.com/hoolee/services/trackbacks/186041.html榪欎竴棰橀鐩湁浜涢暱錛屼笉榪囪繖涓嶅獎鍝嶅畠鏄竴閬撴按棰樸?br />棰樻剰鎻忚堪錛?br />棰樹腑鎻忚堪浜嗕袱縐嶆儏鍐碉紝褰撹緭鍏ユ暟鎹互'P'寮澶存椂錛岃〃紺鴻緭鍏ョ殑鏄?~N鐨勪竴涓帓鍒楋紝瑕佹眰杈撳嚭姣忎釜鏁板墠闈㈡瘮璇ユ暟澶х殑鏁板瓧鐨勪釜鏁幫紝杈撳嚭緇撴灉鏃墮『搴忎負鏁板瓧1鐨勫湪鍓嶏紝鏁板瓧N鐨勫湪鏈鍚庛傜浜岀鎯呭喌姝eソ鐩稿弽錛岀粰鍑烘瘡涓暟瀛楀墠闈㈡瘮璇ユ暟澶х殑鏁板瓧鐨勪釜鏁幫紝瑕佹眰杈撳嚭鍘熷簭鍒椼?br />絎竴縐嶆儏鍐靛ソ璇達紝涓昏鏄浜岀鎯呭喌銆?strong>鎯呭喌浜岀殑瑙f硶鏄寜浠庡悗寰鍓嶉『搴忕‘瀹氬師搴忓垪錛?/strong>鍗沖厛紜畾鏁板瓧N鐨勪綅緗紝鍐嶇‘瀹氭暟瀛桸-1鐨勪綅緗?#8230;…鐩村埌鎵鏈夋暟瀛椾綅緗‘瀹氥傛湡闂翠富瑕佹槸鍏冪礌鐨勬彃鍏ユ搷浣溿?/div>
#include<stdio.h> #include<stdlib.h> #define LEN 60 int num[LEN]; //杈撳叆錛?/span> int rs[LEN];//鎵姹傜粨鏋滐紝涓ょ鎯呭喌鐨勭粨鏋滈兘鐢╮s[]璁板綍銆?/span> int N; void fP() { int i, j, k; int ps; for(i =1; i <= N; i++) { ps =0; while(num[++ps] != i); int count =0; for(k =1; k < ps; k++) if(num[k] > i) count++; rs[i] = count; } } void Insert(int ps, int insertnum, int len)//鎻掑叆鍑芥暟 { int i, j; for(i = len; i >= ps; i--) rs[i +1] = rs[i]; rs[ps] = insertnum; } void fI() { int i, j; int len; rs[1] = N; len =1; for(i = N -1; i >=1; i--) { int ps = num[i] +1; Insert(ps, i, len); len++; } } int main() { int i, j; char c; scanf("%d", &N); while(N !=0) { getchar(); c = getchar(); for(i =1; i <= N; i++) scanf("%d", &num[i]); if(c =='P') fP(); else fI();
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define LEN 4000 int isZero(char*str) { int len = strlen(str); for(int i =0; i < len; i++) if(str[i] !='0') return0; return1; } int RootOne(int n) { int sum =0; while(n !=0) { sum += n %10; n /=10; } return sum; } int Root(char*str) { int i, j; int n =0; int len = strlen(str); for(i =0; i < len; i++) { n += str[i] -'0'; } int sum = n; while(sum /10) { sum = RootOne(sum); } return sum; } int main() { int i, j; char str[LEN]; while(scanf("%s", str) != NULL &&!isZero(str)) { int n = Root(str); printf("%d\n", n); //scanf("%s", str); } //system("pause"); }