Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:1001题:有牛人帮我看下不,提交总是wrong answerIn Reply To:有牛人帮我看下不,提交总是wrong answer Posted by:20085753 at 2010-04-23 22:38:13 > #include <iostream> > #include <vector> > #include <string> > using namespace std; > > void fun(string r, int n){ > vector<int> arr; > int point = 0; > for(int k = r.size() - 1; k >= 0; k--){ > if(r[k] != '.') > arr.push_back(r[k] - 48); > else > point = r.size() - k - 1; > } > int temp = 0, carry = 0, num = n; > vector<int> brr = arr; > vector<int> crr = arr; > while(--num){ > for(unsigned int i = 0; i < brr.size(); i++){ > for(unsigned int j = 0; j < crr.size(); j++){ > temp = brr[i] * crr[j] + carry; > if(i == 0) > arr[j] = temp % 10; > else if(j + i < arr.size()){ > temp += arr[i + j]; > arr[i + j] = temp % 10; > } > else > arr.push_back(temp % 10); > carry = temp / 10; > } > while(carry){ > temp = carry % 10; > arr.push_back(temp); > carry /= 10; > } > } > crr = arr; > } > int leng = 0, stats = 0; > for(unsigned int x = 0; x < arr.size(); x++){ > if(stats == 0 && arr[x] == 0) > leng++; > else{ > stats++; > if(x == arr.size() - point * n + leng - 1 && point != 0) > cout << arr[arr.size() - stats] << "."; > else > cout << arr[arr.size() - stats]; > } > } > if(leng == arr.size()) > cout << 0; > cout << endl; > } > int main(){ > string r; > int n; > while(cin >> r >> n) > fun(r, n); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator