国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1024. Palindromic Number (25)

2019-11-11 02:47:29
字體:
來源:轉載
供稿:網友

題目不難,開始錯誤的原因是用str=tostring(stoll(str)+stoll(str2))來處理結果,導致溢出(str存儲的數值可能會遠超過10^10)

#include<iostream>#include<string>using namespace std;int main(){ string str; cin >> str; int K; cin >> K; int t = 0; while(1) { string str2; for (auto it = str.rbegin();it != str.rend();it++) str2.push_back(*it); if (str == str2 || t==K) break; else { int temp = 0; for (int i = str.size()-1;i >= 0;i--) if (str[i]+str2[i]-'0'-'0'+temp > 9) { str[i] = str[i]-'0' + str2[i] + temp - 10; temp = 1; } else { str[i] = str[i]-'0' + str2[ i] + temp; temp = 0; } if (temp == 1) str.insert(str.begin(), '1'); t++; } } if (t != K + 1) cout << str << endl << t << endl; else cout << str << endl << K << endl;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固镇县| 山东| 南召县| 扶绥县| 环江| 得荣县| 大渡口区| 阳曲县| 陵川县| 虹口区| 平阳县| 建瓯市| 桐柏县| 祁连县| 内乡县| 贵定县| 嘉定区| 青阳县| 阳泉市| 内丘县| 壶关县| 牡丹江市| 津市市| 荆州市| 天峻县| 高邑县| 同心县| 镇雄县| 八宿县| 筠连县| 东阿县| 洪洞县| 高密市| 高碑店市| 郁南县| 桦川县| 军事| 孝义市| 泽普县| 交城县| 隆德县|