10197 - Learning Portuguese

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

Moderator: Board moderators

fuad420
New poster
Posts: 3
Joined: Wed Jul 04, 2007 3:05 pm
Location: East West University

10197 PE!! plz help

Post by fuad420 » Fri Jul 13, 2007 8:52 pm

i am getting PE for this code. I am not sure about the spaces. plz help.

#include<stdio.h>
#include<iostream.h>
#include<string.h>

int main()
{
char str1[100],str2[100],str3[100],ch=243;

int i,j,k,len;

while(cin>>str1>>str2)
{
cout<<str1<<' '<<"(to "<<str2<<")"<<endl;
len=strlen(str1);
if(str1[len-1]=='r'&&str1[len-2]=='a')
{
strcpy(str3,str1);
str3[strlen(str3)-2]='o';
str3[strlen(str3)-1]='\0';
cout<<"eu "<<str3<<endl;//9 spaces
strcpy(str3,str1);
str3[strlen(str3)-1]='s';
cout<<"tu "<<str3<<endl;//9 spaces
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
cout<<"ele/ela "<<str3<<endl;//4 spaces
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"mos");
str3[strlen(str3)]='\0';
cout<<"n"<<ch<<"s "<<str3<<endl;//8 spaces
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"is");
str3[strlen(str3)]='\0';
cout<<"v"<<ch<<"s "<<str3<<endl;//8 spaces
strcpy(str3,str1);
str3[strlen(str3)-1]='m';
cout<<"eles/elas "<<str3<<endl;//2 spaces
}
else if(str1[len-1]=='r'&&str1[len-2]=='e')
{
strcpy(str3,str1);
str3[strlen(str3)-2]='o';
str3[strlen(str3)-1]='\0';
cout<<"eu "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='s';
cout<<"tu "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
cout<<"ele/ela "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"mos");
str3[strlen(str3)]='\0';
cout<<"n"<<ch<<"s "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"is");
str3[strlen(str3)]='\0';
cout<<"v"<<ch<<"s "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='m';
cout<<"eles/elas "<<str3<<endl;
}

else if(str1[len-1]=='r'&&str1[len-2]=='i')
{
strcpy(str3,str1);
str3[strlen(str3)-2]='o';
str3[strlen(str3)-1]='\0';
cout<<"eu "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-2]='\0';
strcat(str3,"es");
cout<<"tu "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-2]='e';
str3[strlen(str3)-1]='\0';
cout<<"ele/ela "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"mos");
str3[strlen(str3)]='\0';
cout<<"n"<<ch<<"s "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-1]='\0';
strcat(str3,"s");
str3[strlen(str3)]='\0';
cout<<"v"<<ch<<"s "<<str3<<endl;
strcpy(str3,str1);
str3[strlen(str3)-2]='\0';
strcat(str3,"em");
cout<<"eles/elas "<<str3<<endl;
}
else cout<<"Unknown conjugation"<<endl;
cout<<endl;
}
return 0;
}[/quote]

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish » Sat Jul 14, 2007 5:13 am

ur output format is not correct. ur output format should follow the output specification.Here u can output like this

Code: Select all

cout << str1 << " (to " << str2 << ")" << endl;
cout << "eu        " << s << endl;
cout << "tu        " << s << endl;
cout << "ele/ela   " << s << endl;
cout << "n" << c <<"s       " << s << endl;
cout << "v" << c <<"s       " << s << endl;
cout << "eles/elas " << s << endl;
You must print a blank line between the output sets , not after each output sets.
Hope this helps.

fuad420
New poster
Posts: 3
Joined: Wed Jul 04, 2007 3:05 pm
Location: East West University

Post by fuad420 » Sat Jul 14, 2007 6:58 am

hi mmonish,
Actually i gave all the blank spaces properly as you mentioned. that means my output format is exactly like

Code: Select all

cout << str1 << " (to " << str2 << ")" << endl; 
cout << "eu        " << s << endl; 
cout << "tu        " << s << endl; 
cout << "ele/ela   " << s << endl; 
cout << "n" << c <<"s       " << s << endl; 
cout << "v" << c <<"s       " << s << endl; 
cout << "eles/elas " << s << endl;
but i am not sure why my code is not showing those blank spaces in the electronic board!!! :o in the board its not showing any blank spaces after
eu, tu, ele/ela...... that's funny,isn't it?

Actually mmonish i am not getting your line

You must print a blank line between the output sets , not after each output sets


would you plz explain it more? here i am not sure which segment is output sets? i think for each input there is a output, and this output is a set,isn't it? like the output generated for "falar talk" is an output set,am i right? i am confused where to place blank line. plz help. Thanks.

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish » Sat Jul 14, 2007 12:12 pm

u have to print a blank line after each test case but not after the last one.
here is an example not from the prob

Code: Select all

input
1
2
output
55

66
I hope u will get the point.

User avatar
Fuad Hassan EWU
New poster
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

Post by Fuad Hassan EWU » Tue Jul 17, 2007 3:28 pm

thanks mmonish. i got AC. :D
Eagle er moto daana meley urbo

rneves
New poster
Posts: 1
Joined: Thu Feb 21, 2008 9:51 pm

10197 - Runtime Error

Post by rneves » Thu Feb 21, 2008 9:55 pm

Hi all,

I'm getting runtime error don't know the reason :| Don't know if i'm calling anything wrong but i don't think so...

#include<stdio.h>
#include<string.h>
#include<malloc.h>

char * calcSufixo(char *strPt);

char * calcRoot(char *strPt);

void presentVerb(char *root,char *sufixo,char *strEn);

int main(){

char strPt[30];
char strEn[30];

char input[31];

char *sufixo;
char *root;

int first=0;

while(fgets(input,sizeof(char)*31,stdin)!=NULL){

if(first!=0)
printf("\n");

first++;

input[strlen(input)-1]='\0';

sscanf(input,"%s %s",strPt,strEn);

sufixo=calcSufixo(strPt);
root=calcRoot(strPt);

presentVerb(root,sufixo,strEn);
}

return 0;

}

void presentVerb(char *root,char *sufixo,char *strEn){

char o=243;

printf("%s%s (to %s)\n",root,sufixo,strEn);
if(strcmp(sufixo,"ar")==0){
printf("eu %so\n",root);
printf("tu %s%cs\n",root,sufixo[0]);
printf("ele/ela %s%c\n",root,sufixo[0]);
printf("n%cs %s%cmos\n",o,root,sufixo[0]);
printf("v%cs %s%cis\n",o,root,sufixo[0]);
printf("eles/elas %s%cm\n",root,sufixo[0]);

}
else if(strcmp(sufixo,"er")==0){
printf("eu %so\n",root);
printf("tu %s%cs\n",root,sufixo[0]);
printf("ele/ela %s%c\n",root,sufixo[0]);
printf("n%cs %s%cmos\n",o,root,sufixo[0]);
printf("v%cs %s%cis\n",o,root,sufixo[0]);
printf("eles/elas %s%cm\n",root,sufixo[0]);
}
else if(strcmp(sufixo,"ir")==0){
printf("eu %so\n",root);
printf("tu %ses\n",root);
printf("ele/ela %se\n",root);
printf("n%cs %s%cmos\n",o,root,sufixo[0]);
printf("v%cs %s%cs\n",o,root,sufixo[0]);
printf("eles/elas %sem\n",root);
}
else
printf("Unknown conjugation\n");

}

char * calcSufixo(char *strPt){
char *sufixo=malloc(sizeof(char)*2);

sufixo=&strPt[strlen(strPt)-2];

return sufixo;
}

char * calcRoot(char *strPt){
int sizeRoot=strlen(strPt)-2;

char *root=malloc(sizeof(char)*sizeRoot);
strncat(root,strPt,strlen(strPt)-2);

return root;
}

Thanks

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10197 - Learning Portuguese

Post by stcheung » Wed Oct 08, 2008 10:17 am

Code: Select all

import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;

class Main {	
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));	
	static int[] intBuffer = new int[0];
	static int intBufferPos = 0;
	static double[] doubleBuffer = new double[0];
	static int doubleBufferPos = 0;
	static StringBuilder outputBuffer = new StringBuilder(10000);
	static Scanner scanner = new Scanner(new BufferedInputStream(System.in));
	
	static int[] readIntArr() throws Exception {
		while(true) {
			String line = readLine();
			if(line == null) 
				return null;
			else if(line.equals(""))
				continue;
			else return toIntArr(line);
		}
	}
	
	static int[] toIntArr(String str) {
		if(str.equals(""))
			return new int[0];
		
		String strArr[] = toStrArr(str);
		int intArr[] = new int[strArr.length];
		for(int i=0; i<strArr.length; i++)
			intArr[i] = toInt(strArr[i]);
		
		return intArr;
	}
	
	static int readInt() throws Exception {
		while(intBufferPos >= intBuffer.length) {
			intBuffer = readIntArr();
			intBufferPos = 0;
		}
		return intBuffer[intBufferPos++];
	}
	
	static int toInt(String str) {
		return Integer.parseInt(str);
	}
	
	static long toLong(String str) {
		return Long.parseLong(str);
	}
	
	static double[] readDoubleArr() throws Exception {
		while(true) {
			String line = readLine();
			if(line == null) 
				return null;
			else if(line.equals(""))
				continue;
			else return toDoubleArr(line);
		}
	}
	
	static double[] toDoubleArr(String str) {
		if(str.equals(""))
			return new double[0];
		
		String strArr[] = toStrArr(str);
		double doubleArr[] = new double[strArr.length];
		for(int i=0; i<strArr.length; i++)
			doubleArr[i] = toDouble(strArr[i]);
		
		return doubleArr;
	}
	
	static double readDouble() throws Exception {
		while(doubleBufferPos >= doubleBuffer.length) {
			doubleBuffer = readDoubleArr();
			doubleBufferPos = 0;
		}
		return doubleBuffer[doubleBufferPos++];
	}
	
	static double toDouble(String str) {
		return Double.parseDouble(str);
	}
	
	static String[] toStrArr(String str) {
		StringTokenizer st = new StringTokenizer(str);
		String strArr[] = new String[st.countTokens()];
		int i=0;
		while(st.hasMoreTokens()) {
			strArr[i++] = st.nextToken();
		}
		return strArr;
	}
	
	static String[] readStrArr() throws Exception {
		while(true) {
			String line = readLine();
			if(line == null) 
				return null;
			else if(line.equals(""))
				continue;
			return toStrArr(line);
		}
	}
	
	static String readLine() throws Exception {		
		return br.readLine();
	}
	
	static boolean isEmpty(String s) {
		return (s == null || s.equals(""));
	}
	
	static void flush() {
		System.out.print(outputBuffer.toString());
		outputBuffer = new StringBuilder(10000);
	}
	
	static void print(int n) {
		outputBuffer.append(n);
	}
	
	static void print(long n) {
		outputBuffer.append(n);
	}
	
	static void print(char ch) {
		outputBuffer.append(ch);
	}
	
	static void print(String s) {
		outputBuffer.append(s);
	}
	
	static void println() {
		outputBuffer.append("\n");
	}
	
	static void println(int n) {
		outputBuffer.append(n + "\n");
	}
	
	static void println(long n) {
		outputBuffer.append(n + "\n");
	}
	
	static void println(double n) {
		outputBuffer.append(n + "\n");
	}
	
	static void println(String s) {
		outputBuffer.append(s + "\n");
	}
	
	static int max(int a, int b) {
		return (a>=b ? a : b);
	}
	
	static int min(int a, int b) {
		return (a<b ? a : b);
	}
	
	static int max(int[] intArr) {
		int max = intArr[0];
		for(int i=1; i<intArr.length; i++) {
			if(intArr[i] > max)
				max = intArr[i];
		}
		return max;
	}
	
	static long abs(long n) {
		return Math.abs(n);
	}
	
	static void myassert(boolean b) throws Exception {
		if(!b)
			throw new Exception("BAD");
	}
	
	public static void main(String args[]) throws Exception {
		boolean newline = false;
		while(true) {
			String line = readLine();
			if(line == null) break;
			int space = line.indexOf(" ");
			String verb = line.substring(0, space).trim();
			String meaning = line.substring(space + 1).trim();
			
			if(newline)
				println();
			else newline = true;
			println(verb + " (to " + meaning + ")");
			int len = verb.length();
			if(len < 2) {
				println("Unknown conjugation");
				continue;
			}
			
			String root = verb.substring(0, len-2);
			String lastTwoChar = verb.substring(len-2);
			char tv = ' ';			
			if(lastTwoChar.equals("ar")) {
				tv = 'a';
			} else if(lastTwoChar.equals("er")) {
				tv = 'e';
			} else if(lastTwoChar.equals("ir")) {
				tv = 'i';
			} else {
				println("Unknown conjugation");
				continue;
			}
			
			String a = (root + "o");
			String b = (tv == 'i' ? root + "es" : root + tv + "s");
			String c = (tv == 'i' ? root + "e" : root + tv);
			String d = (root + tv + "mos");
			String e = (tv == 'i' ? root + tv + "s" : root + tv + "is");
			String f = (tv == 'i' ? root + "em" : root + tv + "m");
			
			println("eu        " + a);
			println("tu        " + b);
			println("ele/ela   " + c);
			println("n" + (char)243 + "s       " + d);
			println("v" + (char)243 + "s       " + e);
			println("eles/elas " + f);
		}
		flush();
	}
}
I suspect this is another problem where you can't get accepted with Java. I ended up writing the same program in C++ instead. Please let me know if you spot any issue with the above code or got accepted in Java. Thanks.

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Re: 10197 - Learning Portuguese

Post by alamgir kabir » Fri May 22, 2009 9:37 pm

I think I am ok. But I am getting WA.
can anyone explain why?
I will be greatful to him.

Code: Select all

#include<stdio.h>
#include<string.h>

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);

    char latin [ 40 ], english [ 40 ], str [ 100 ], *tok;
    char pronoun [][ 50 ] = {"eu        ","tu        ","ele/ela   ","nós       ","vós       ","eles/elas "},con1 [][ 10 ] = {"o", "as","a","mos","ais","am"}, con2 [][ 10 ]= {"o", "es","e","emos","eis","em"}, con3 [][ 10 ]= {"o", "es","e","imos","is","em"};
    int i, len, kase = 0;

    while( gets( str ) )
    {
        tok = strtok( str, " ");
        strcpy( latin, tok );

        tok = strtok(NULL, "");
        strcpy(english, tok);

        len = strlen( latin );
        if( kase ) printf("\n"); kase = 1;
        printf("%s (to %s)\n", latin, english);
        if( latin [ len  - 1 ] != 'r' || len < 2 )
        {
            printf("Unknown conjugation\n");
            continue;
        }
        if( latin [ len - 2 ] == 'a' && latin [ len - 1 ] == 'r' )
        {
            latin [ len - 2 ] = '\0';
            for( i = 0; i < 6; i ++)
            {
                printf("%s%s%s\n", pronoun [ i ], latin, con1 [ i ]);
            }
        }
        else if( latin [ len - 2 ] == 'e' && latin [ len - 1 ] == 'r' )
        {
            latin [ len - 2 ] = '\0';
            for( i = 0; i < 6; i ++)
            {
                printf("%s%s%s\n", pronoun [ i ], latin, con2 [ i ]);
            }
        }
        else if( latin [ len - 2 ] == 'i' && latin [ len - 1 ] == 'r' )
        {
            latin [ len - 2 ] = '\0';
            for( i = 0; i < 6; i ++)
            {
                printf("%s%s%s\n", pronoun [ i ], latin, con3 [ i ]);
            }
        }
        else
        {
             printf("Unknown conjugation\n");
        }

    }
    return 0;
}

Thanks
alamgir

Bruno
New poster
Posts: 22
Joined: Thu Oct 01, 2009 9:03 pm

Re: 10197 - Learning Portuguese

Post by Bruno » Wed Oct 28, 2009 10:01 pm

I am getting WA too, and I dont know why! :o

Look out my code:

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int main()
{
    	bool flag = 0;
    	string portuguese,english;
    	char tv;
   
    	while (cin >> portuguese >> english)
    	{
        	if (!flag)
        		flag = 1;
        	else
        		cout << endl;

		cout << portuguese << " (" << "to " << english << ")" << endl;
		
		if (portuguese.size() > 1)
		{
			tv = portuguese[portuguese.size()-2];
			portuguese = portuguese.substr(0,portuguese.size()-2);
		}
		else
			tv = 'x';
		
		if (tv == 'a' || tv == 'e')
		{
		    	cout << "eu        " << portuguese << 'o' << endl;
		    	cout << "tu        " << portuguese << tv << 's' << endl;
		    	cout << "ele/ela   " << portuguese << tv << endl;
		    	cout << "n" << (char)243 << "s       " << portuguese << tv << "mos" << endl;
		    	cout << "v" << (char)243 << "s       " << portuguese << tv << "is" << endl;
		    	cout << "eles/elas " << portuguese << tv << 'm' << endl;
		}
		else if (tv == 'i')
		{
		    	cout << "eu        " << portuguese << 'o' << endl;
		    	cout << "tu        " << portuguese << "es" << endl;
		    	cout << "ele/ela   " << portuguese << 'e' << endl;
		    	cout << "n" << (char)243 << "s       " << portuguese << tv << "mos" << endl;
		    	cout << "v" << (char)243 << "s       " << portuguese << tv << 's' << endl;
		    	cout << "eles/elas " << portuguese << "em" << endl;
		}
		else
		{
		    	cout << "Unknown conjugation" << endl;
		}
	}
	return 0;
}

gtcoder
New poster
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

Re: 10197 - Learning Portuguese

Post by gtcoder » Wed Sep 22, 2010 12:07 am

You can't use the "nos" and "vos" as copy-paste strings in the array. For them you have to use 243 explicitly.


Like this:

Code: Select all

for (i=0 ; i<6 ; i++) {
        if (i==3) {
            putchar('n'); putchar(243); putchar('s');
        } else if (i==4) {
            putchar('v'); putchar(243); putchar('s');
        } else
            printf("%s",t_rep[i]);
        for (j=1 ; j<11-strlen(t_rep[i]) ; j++) {
            putchar(' ');
        }
        printf("%s%s\n",str,c_rep[con][i]);
    }
I think the reason for this is that 243 falls under the territory of "unsigned char". And if you use an array for the printing process then you can't STRLEN() on them using normal array pointing (or whatever).

Another problem I'm facing is that I'm getting AC only when I'm submitting in C++. In C, the same code is giving PE.
EDIT: Now I got AC in C too. The Unsigned Char issue is the thing. And strlen() can't calculate properly if string contains Unsigned Char.

nguyenh3
New poster
Posts: 5
Joined: Mon Sep 20, 2010 5:53 pm

Re: 10197 - Learning Portuguese

Post by nguyenh3 » Thu Sep 23, 2010 6:34 am

I got WA with my code.
It has been a very frustrating experience.

Code: Select all

import java.util.*;

public class Main {	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		char[] nos = {'n', 243, 's'};
		char[] vos = {'v', 243, 's'};
		String[][] conjugations = {{"eu", "tu", "ele/ela", new String(nos), new String(vos), "eles/elas"},
				{"o", "as", "a", "amos", "ais", "am"},
				{"o", "es", "e", "emos", "eis", "em"},
				{"o", "es", "e", "imos", "is", "em"},};
		String thematicVowels = " aei";
		String pt, en;
		int conjugation;
		while (scanner.hasNextLine()) {
			pt = scanner.nextLine();
			conjugation = pt.indexOf(' ');
			en = pt.substring(conjugation + 1);
			pt = pt.substring(0, conjugation);
			conjugation = thematicVowels.indexOf(pt.charAt(Math.max(pt.length() - 2, 0)));
			System.out.println(pt + " (to " + en + ")");
			
			if (conjugation == -1 || !pt.endsWith("r")) {
				System.out.println("Unknown conjugation");
			} else {
				pt = pt.substring(0, pt.length() - 2);
				for (int i = 0; i < 6; i++) {
					print(conjugations[0][i], 10);
					System.out.println(pt + conjugations[conjugation][i]);
				}
			}
			
			if (scanner.hasNextLine())
				System.out.println();
		}
		
		scanner.close();
	}
	
	private static void print(String s, int pad) {
		System.out.print(s);
		for (int i = 0; i < pad - s.length(); i++) {
			System.out.print(' ');
		}
	}
}

gtcoder
New poster
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

Re: 10197 - Learning Portuguese

Post by gtcoder » Thu Sep 23, 2010 8:14 pm

nguyenh3 wrote:I got WA with my code.
It has been a very frustrating experience.
Tip 1: Test these

Code: Select all

ir is there something wrong?
ar ar
falar        what is this
namer   coder
jubir jubir
Outputs

Code: Select all

ir (to is there something wrong?)
eu        o
tu        es
ele/ela   e
nós       imos
vós       is
eles/elas em

ar (to ar)
eu        o
tu        as
ele/ela   a
nós       amos
vós       ais
eles/elas am

falar (to what is this)
eu        falo
tu        falas
ele/ela   fala
nós       falamos
vós       falais
eles/elas falam

namer (to coder)
eu        namo
tu        names
ele/ela   name
nós       namemos
vós       nameis
eles/elas namem

jubir (to jubir)
eu        jubo
tu        jubes
ele/ela   jube
nós       jubimos
vós       jubis
eles/elas jubem
Tip 2: I don't know Java that well to debug your code. Not even what I'm talking about. But is there something like unsigned char and char difference in Java? If so, then the string length calculation is bound to fail. In my case that's what happened. I assigned like this:

Code: Select all

unsigned char t_rep[6][30]={"eu","tu","ele/ela","nós","vós","eles/elas"};
While printing, I printed all the string using loop even the nos vos. I got WA
Then I used the exceptions n243s and v243s but still WA
Then

Code: Select all

char t_rep[6][30]={"eu","tu","ele/ela","nós","vós","eles/elas"};
Which is totally illogical so WA
Then I did

Code: Select all

char t_rep[6][30]={"eu","tu","ele/ela","nss","vss","eles/elas"};
Did the strlen() on these and the exceptions too were used. AC.

I think strlen() has some prob with that or something. Hope this info helps. I understand how damn frustrating it can get.

nguyenh3
New poster
Posts: 5
Joined: Mon Sep 20, 2010 5:53 pm

Re: 10197 - Learning Portuguese

Post by nguyenh3 » Thu Sep 23, 2010 9:51 pm

Tip 1: Test these

Code: Select all

ir is there something wrong?
ar ar
falar        what is this
namer   coder
jubir jubir
I see what you mean - that the English word doesn't necessarily start one space after the Portuguese word. So I added a trim() function which takes out all trailing spaces (before and at the end of the string).
I still get WA.

Java doesn't have unsigned variables. I'm pretty confident the String.length() counts correctly all characters, including (char) 243.
I really appreciate your input to my problem though. Thanks.

annhy
New poster
Posts: 40
Joined: Sun May 27, 2007 1:42 am
Location: Taiwan

Re: 10197 - Learning Portuguese

Post by annhy » Fri Apr 01, 2011 11:43 am

I finally got AC with Java... (I hate this problem. :-? )

Some things about Java:
1. In Java, char is always unsigned.

2. Java will automatically encodes the output to your default character set.
For example, "Big5" is for Traditional Chinese, "GB18030" is for Simplified Chinese, "KOI8-R" is for Russian.
I guess the most used encoding of Windows PCs is "UTF-8".
However, the on-line judge I/O is encoded in "ISO-8859-1".

For Java users, I got AC by the code like this:

Code: Select all

  StringBuffer buf = new StringBuffer();
  OutputStreamWriter cout = new OutputStreamWriter(System.out, "ISO-8859-1");
  
  // your code here
  
  cout.write(buf.toString());
  cout.flush();

nguyenh3
New poster
Posts: 5
Joined: Mon Sep 20, 2010 5:53 pm

Re: 10197 - Learning Portuguese

Post by nguyenh3 » Sat Aug 20, 2011 3:37 am

Thank you annhy, my solution was finally accepted.

This shouldn't be an issue at all.

Post Reply

Return to “Volume 101 (10100-10199)”