| ||||||||||
| 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:C++参考In Reply To:C++参考 Posted by:freelark at 2016-12-28 15:15:21 > #include <iostream>
> #include <sstream>
> #include <stdlib.h>
> #include <string>
> using namespace std;
>
> string inventory(string n)
> {
> stringstream ss;
> int temp[10] = {0};
> int j = 0;
> for (int i = 0; i < n.length(); ++i)
> {
> j = n[i]- 48;
> temp[j] +=1;
> }
> for (int i = 0; i < 10; ++i)
> {
> if (temp[i]>0){
> ss << 10*temp[i] + i;
> }
> }
> return ss.str();
> }
> int main(){
> string s,inventory_s;
> string inventory_list[15];
> while (cin >> s)
> {
> inventory_s = "";
> bool flag = false;
> if (s != "-1")
> {
> cout << s;
> for (int i = 0; i < 15; i++)
> {
> inventory_list[i] = s;
> s = inventory(s);
> for (int j = 0; j <= i; j++)
> {
> if (s == inventory_list[j])
> {
> if (i == j && j == 0)
> printf(" is self-inventorying");
> else if (i == j && j > 0)
> printf(" is self-inventorying after %d steps", j);
> else
> printf(" enters an inventory loop of length %d ", (i-j+1));
> flag = true;
> break;
> }
> }
> if (flag)
> break;
> else if (i==14)
> cout << " can not be classified after 15 iterations";
> }
> }
> cout << endl;
> }
> system("pause");
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator