10602 - Editor Nottoobad

All about problems in Volume 106. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

medv
Learning poster
Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

10602 - RTE. Help me!

Post by medv » Sun Feb 19, 2006 5:05 pm

Why RTE???? Where is Error?
I tried to increase array size - but it didn't help

#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int tests,i,n;
string s[100];
int len,res;

int common(int i, int j)
{
int k;
for(k=0;k<s.size(),k<s[j].size();k++)
if (s[k] != s[j][k]) break;
return k;
}

int lt(string s1, string s2)
{
int i,j;
for(i=0;i<s1.size(),i<len;i++)
if (s1 != s[0]) break;
for(j=0;j<s2.size(),j<len;j++)
if (s2[j] != s[0][j]) break;
if (i < j) return 0;
if ((i == j) && (s1 > s2)) return 0;
return 1;
}

int main (void)
{
char temp[101];
scanf("%d",&tests);
while(tests--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",temp);
s = string(temp);
}
len = s[0].size();
sort(s+1,s+n,lt);
res = len;
for(i=1;i<n;i++)
res += (s.size() - common(i-1,i));
printf("%d\n",res);
for(i=0;i<n;i++)
printf("%s\n",s.c_str());
}
return 0;
}

joshi13
New poster
Posts: 9
Joined: Sun Jan 06, 2008 3:18 am

WA in 10602

Post by joshi13 » Wed Jan 23, 2008 5:14 pm

Hi, i've also used the greedy choice as previous posts suggested, but i keep getting WA. Pls need some critical I/O.
(Note: For the frist input case of the problem, my code outputs:
3
this thing thin

which also leads to only 6 presses, and the problem says: "If there are several solutions, you can output one of them.
"
)

Thanks in advance.

Code: Select all

#include<iostream>
#include<cstring>
#include<algorithm>

#define MAX 150

using namespace std;

typedef struct {
    char str[MAX];
    int  prefix;
} Word;    

bool fun(Word a, Word b) {
     if(a.prefix != b.prefix) return a.prefix > b.prefix;
     return strcmp(a.str,b.str);
}

Word words[MAX];

int main() {
    
    int T; cin >> T;
    int n, ans;    
    int i, j;
    char temp[MAX];
    
    while(T--) {

        cin >> n;
        ans = 0;
        
        for(i = 0; i < n; i++) cin >> words[i].str;
        words[0].prefix = strlen(words[0].str);
        strcpy(temp,words[0].str);
        ans = words[0].prefix;

        
        for(i = 1; i < n; i++) {
              j = 0;
              while(temp[j] && words[i].str[j] && temp[j] == words[i].str[j]) j++;
              words[i].prefix = j;              
        }
        sort(words+1, words + n, fun);
        
        for(i = 1; i < n; i++) {
              
              j = 0;
              while(words[i-1].str[j] && words[i].str[j] && words[i-1].str[j] == words[i].str[j]) j++;
              
              ans += strlen(words[i].str) - j;
              
        } 
              
        cout << ans << endl;
        for(i = 0; i < n; i++) cout << words[i].str << endl;
        
    } 
}     

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 10602 - Editor Nottobad

Post by Articuno » Wed Dec 24, 2008 5:00 pm

I am getting WA. Don't know why. Can anyone give me some test cases please?
Thanks in advance.
May be tomorrow is a better day............ :)

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 10602 - Editor Nottobad

Post by Articuno » Wed Dec 24, 2008 6:35 pm

AC at last. :)
If anyone getting WA, try the following case:

Code: Select all

1
4
abcd
abxy
abuv
abxy
One possible result is:

Code: Select all

8
abcd
abuv
abxy
abxy
May be tomorrow is a better day............ :)

mathfxr
New poster
Posts: 3
Joined: Fri Sep 17, 2010 11:44 am

Re: 10602 - Editor Nottobad runtime error exit 0

Post by mathfxr » Fri Sep 17, 2010 4:13 pm

Hi there , i tried to solve this problem using JAVA, and when i submit to UVA in keep give me the same error
"Your submission with number 8257231 for the problem 10602 - Editor Nottoobad has failed with verdict Runtime error.


This means that the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0.
",
i already revised it too many times.This code is working using my machine.
here is my code.
any ideas?
i try to avoid using arraylist or linkedlist

Code: Select all

import java.util.*;
import java.text.Collator;

class BruteForces {

    public static int totalsum=0;
    public static String outputAll1="";
    public static String outputAll2="";

    public static void main(String[] args) {

            String[] InputDatasLoopAr1=new String[100];
            String[] InputDatasLoopAr2=new String[100];
        //iniatialize array;
            for(int i = 0; i <100; i++) {
                InputDatasLoopAr1[i] = new String();
                 InputDatasLoopAr2[i] = new String();
            
            }

        Scanner in = new Scanner(System.in);//use system.in to read input


        int Intdatacase=0;
        String datacase="";
        //get data case
       try { datacase = in.next();
        Intdatacase=Integer.parseInt(datacase);
        } catch ( Exception e) { System.exit(0); }
        if ( datacase == null ) System.exit(0);

        
        int intLoop=0,IntInputsz=0;
        String InputDatas="";
        while(intLoop<Intdatacase){
          outputAll1="";
          outputAll2="";
          //get input for each case
           InputDatas="";

             
          String InputDatas2 ="";
          //get how many words in a cases
                try { IntInputsz = in.nextInt();
                
                        } catch ( Exception e) { break; }
                
                //enter first words
                try{
                
                 InputDatas = in.next();

                   } catch ( Exception e) { break; }
                    if ( InputDatas == null ) break;

                for(int i=0;i<IntInputsz-1;i++)
                {
        
                            String InputDatasLoop="";
                            //get next word if size word >1
                            try { InputDatasLoop = in.next();  } catch ( Exception e) { 
                                
                                break; }
                            if ( InputDatasLoop == null ) {break;}

                    if(InputDatasLoop.charAt(0)==InputDatas.charAt(0))
                                {
                                    InputDatasLoopAr1[i]=InputDatasLoop;
                                }
                    else
                                InputDatasLoopAr2[i]=InputDatasLoop;
                  
                }

            
    

                sortArray(InputDatasLoopAr1);//sort first array
                sortArray(InputDatasLoopAr2);//sort second array
                totalsum=InputDatas.length();//get first value of word
                outputAll1=InputDatas;//insert first word
                calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array
                InputDatas="";//clear inputdatas
                calculate(InputDatasLoopAr2,InputDatas,"D",totalsum);//calculate for second array
                System.out.printf(totalsum+"\n"+outputAll1+"\n"+outputAll2);//display output
                
        intLoop++;
        
        }

        
        System.exit(0);
    }
   
public static void calculate(String[] strArray,String InputDatas,String Arrange,int total)
{               int LastIndex=InputDatas.length(),counts=1;
                Boolean InputDatasB=false;

      for(int iz=0;iz<100;iz++)
        {

          if(strArray[99].isEmpty())
          {
              break;

              }

          if((InputDatasB==true&&!strArray[iz].isEmpty())||(InputDatas.equals("")&&!strArray[iz].isEmpty()))
          {
             InputDatas=strArray[iz];
             LastIndex=strArray[iz].length();
             InputDatasB=false;
             totalsum+=LastIndex;

          }
            int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));
            if(pos2==0&&!strArray[iz].isEmpty())
            {
                    if(Arrange.equals("D"))
                    outputAll2=strArray[iz]+"\n"+outputAll2;
                    else
                    outputAll1=outputAll1+"\n"+strArray[iz];

                    totalsum+=(strArray[iz].length()-LastIndex);

                    InputDatas=strArray[iz];
                    LastIndex=strArray[iz].length();
                    strArray[iz]="";
            }
            int CountNext=iz+1;
            if(CountNext==strArray.length)
            {
                if(counts==1)
                {

                 iz=0;
                 LastIndex--;
                 sortArray(strArray);
                }

                if(LastIndex==0)
                {  sortArray(strArray);
                   InputDatasB=true;
                   return;
                }
            }
        }
        return;

}
    public static void sortArray(String[] strArray){
                String tmp;
         Collator collator = Collator.getInstance(Locale.UK);

                if (strArray.length == 1) return;
                for (int i = 0; i < strArray.length;i++) {
                    for (int j = i + 1; j < strArray.length; j++) {
                        if( collator.compare(strArray[i], strArray[j] ) > 0 ) {
                        tmp = strArray[i];
                        strArray[i] = strArray[j];
                        strArray[j] = tmp;
                        }
                    }
                }
                return;
    }

}

Post Reply

Return to “Volume 106 (10600-10699)”