zoukankan      html  css  js  c++  java
  • poj1026

    模拟题

    View Code
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    using namespace std;
    
    #define maxn 205
    
    int n, m, len;
    int f[maxn];
    char st[maxn];
    bool vis[maxn];
    int circle_num;
    int circle[maxn];
    int circle_length[maxn];
    char ans[maxn];
    
    void make()
    {
        memset(vis, 0, sizeof(vis));
        circle_num = 0;
        for (int i = 0; i < n; i++)
            if (!vis[i])
            {
                int num = 0, temp = i;
                while (!vis[temp])
                {
                    vis[temp] = true;
                    circle[temp] = circle_num;
                    num++;
                    temp = f[temp];
                }
                circle_length[circle_num++] = num;
    //            printf("%d\n", num);
            }
    }
    
    void input()
    {
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &f[i]);
            f[i]--;
        }
        make();
        while (scanf("%d", &m), m)
        {
            getchar();
            len = 0;
            gets(st);
            len = strlen(st);
            for (int i = len; i < n; i++)
                st[i] = ' ';
            st[n] = '\0';
            for (int i = 0; i < n; i++)
            {
                int j = m % circle_length[circle[i]];
                int temp = i;
                while (j--)
                    temp = f[temp];
                ans[temp] = st[i];
            }
            ans[n] = '\0';
            printf("%s\n", ans);
        }
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        while (scanf("%d", &n), n)
        {
            input();
            putchar('\n');
        }
        return 0;
    }
  • 相关阅读:
    java的堆和栈
    概率题
    并发复习在回顾
    hashmap和hashtable
    StringBuilder和StringBuffer
    WinSCP 工具
    网络桥接注意问题。
    虚拟机网络设置
    Spring任务计划
    Spring任务执行器(TaskExecutor)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2579375.html
Copyright © 2011-2022 走看看