| Zhenyu's profile熊归来PhotosBlogLists | Help |
|
September 28 女孩今天听一个女孩说起她最想做的几件事: 1.去麦当劳打工 2.救助流浪猫 3.学钢琴 4.打网球 5.练习跆拳道 6.做瑜伽 7.戴着iShuffle上跑步机 8.去教会礼拜 说实话挺俗的。俗不可耐。俗,就是说和大众的口味一样。用别人的标准来要求自己,做什么都是给别人看。 September 22 纯洁的心灵写一篇很纯的C++。
#include <iostream>
#include <iomanip> #include <string>
#include <sstream> #include <vector>
#include <algorithm> #include <cmath>
#include <cassert> using namespace std;
string trim(const string& str) {
return str.substr(0, str.find_last_not_of(" ")+1); } int main(int argc, char** argv) {
istringstream iss("1000 10000 100 100000 10"); vector<int> lls; for(int i; iss.good(); iss>>i, lls.push_back(i)) ; sort(lls.begin(), lls.end()); ostringstream oss; for(int i=0; i<(int)lls.size(); oss<<lls[i++]<<" ") ; oss.str(trim(oss.str())); assert(oss.str().length()==iss.str().length()); cout.setf(ios::fixed); for(int i=0; i<min((int)lls.size(), 10); i++) { cout<<setprecision(i+2)<<setw(i+12)<<(float)lls[i]<<endl; } return 0; } 运行结果: zyzhang@virtue ~> g++ sample.cpp && ./a.out 10.00 100.000 1000.0000 10000.00000 100000.000000 zyzhang@virtue ~> |
|
|