Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么总是runtime error?太奇怪了。

Posted by bupt00x0b at 2017-03-01 14:38:33 on Problem 1026
#include<stdio.h>
#include<iostream>
#include<limits.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int MAX = 210;
int number[MAX];
char character[MAX];
char temp[MAX];
int circle[MAX][MAX];


int main(int argc, char *argv[]){
    int n,k;
    //cout<<~0<<endl;
    while(~scanf("%d",&n)&& n!=0) {
        for (int i=0; i<n; i++) {
            scanf("%d",number+i);
            number[i] -= 1;
        }
      while(~scanf("%d",&k) && k ){
        for (int i=0; i<n; i++)
            circle[0][i] = number[i];
        int T=0;
        for (int i=1; ; i++) {
            for(int j=0; j<n; j++) {
                circle[i][number[j]] = circle[i-1][j];
            }
            bool flag = true;
            for (int j=0; j<n; j++)
                if (circle[0][j] != circle[i][j]){
                    flag = false;
                    break;
                }
            if (flag){
                T = i;
                break;
            }
        }
        k = k%T;//figure out the cycle first;


        memset(character,0,sizeof(character));
        memset(temp,     0,sizeof(temp));
        getchar();
        gets(character);
        bool flag = true;
        while(k--) {
          if (flag) {
           // cout<<"flag is true"<<endl;
              for (int i=0; i<n; i++) {
                temp[number[i]] = character[i];
            }
            int i;
            for ( i=203; i>=0; i--) {
                if (temp[i]!=0)
                    break;
            }
            temp[i+1] = 0;
            for(int j = i; j>=0; j--)
                if (temp[j]==0)
                    temp[j]=' ';
            flag = (!flag);

          } else {
              //cout<<"flag is false"<<endl;
                for (int i=0; i<n; i++) {
                    character[number[i]] = temp[i];
                }
                int i;
                for (i=203; i>=0; i--)
                    if (character[i]!=0)
                        break;
                character[i+1] = 0;
                for(int j=i; j>=0; j--) {
                    if (character[j] == 0)
                        character[j] = ' ';

                }
                flag = (!flag);
          }

        }
        if (!flag)
            puts(temp);
        else{
            puts(character);
            //cout<<"else"<<endl;
        }

        //cout<<"get temp"<<endl;
      }


    printf("\n");
    }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator