Code: Select all
Code Deleted After Solved!! :)
Moderator: Board moderators
Code: Select all
Code Deleted After Solved!! :)
Code: Select all
#include<stdio.h>
#include<string.h>
int rev(int n)
{
int x=0,q=0,s=0,t=0;
s=n;
if(s>99)
{
x=100;
while(s!=0)
{
q=s%10;
s/=10;
t=t+(q*x);
x/=10;
}
}
else
{
x=10;
while(s!=0)
{
q=s%10;
s/=10;
t=t+(q*x);
x/=10;
}
}
return t;
}
void disOutput(char str[81])
{
int n=1,i,s=0;
for(i=strlen(str)-1;i>=0;i--)
{
if((int)str[i]>=48 && (int)str[i]<=57)
{
s+=((int)str[i]-48)*n;
n*=10;
if(s>=32)
{
printf("%c",(char)rev(s));
s=0,n=1;
}
}
else
{
printf("%d",rev((int)str[i]));
}
}
printf("\n");
return 0;
}
void main()
{
char str[81];
while(gets(str))
disOutput(str);
return 0;
}
I used return 1; but again RE!!brianfry713 wrote:main should return int.
Code: Select all
import java.io.*;
import java.util.HashMap;
import java.util.Map;
class Main {
public static void main(String[] args) {
Map<Character, Integer> codes = new HashMap<Character, Integer>();
Map<Integer, Character> decodes = new HashMap<Integer, Character>();
for (int i = 'A'; i <= 'Z'; i++) {
codes.put((char) i, i - 'A' + 65);
decodes.put(i - 'A' + 65, (char) i);
}
for (int i = 'a'; i <= 'z'; i++) {
codes.put((char) i, i - 'a' + 97);
decodes.put(i - 'a' + 97, (char) i);
}
codes.put(' ', 32);
codes.put('!', 33);
codes.put(',', 44);
codes.put('.', 46);
codes.put(':', 58);
codes.put(';', 59);
codes.put('?', 63);
decodes.put(32, ' ');
decodes.put(33, '!');
decodes.put(44, ',');
decodes.put(46, '.');
decodes.put(58, ':');
decodes.put(59, ';');
decodes.put(63, '?');
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
try {
String line;
while ((line = reader.readLine()) != null) {
StringBuilder result = new StringBuilder();
if (Character.isLetter(line.charAt(0))) {
encode(line, result, codes);
} else {
decode(line, result, decodes);
}
writer.write(result.append('\n').toString());
}
writer.flush();
} catch (IOException e) {
}
}
private static void encode(String line, StringBuilder result, Map<Character, Integer> codes) {
char[] lineArray = line.toCharArray();
reverse(lineArray);
for (Character c : lineArray) {
char[] chars = codes.get(c).toString().toCharArray();
reverse(chars);
for (char aChar : chars) {
result.append(aChar);
}
}
}
private static void reverse(char[] chars) {
for (int i = 0; i < chars.length / 2; i++) {
char tmp = chars[i];
int switchIntdex = chars.length - 1 - i;
chars[i] = chars[switchIntdex];
chars[switchIntdex] = tmp;
}
}
private static void decode(String line, StringBuilder result, Map<Integer, Character> codes) {
int startIndex = 0;
int endIndex = 1;
char[] chars = line.toCharArray();
reverse(chars);
while (endIndex < chars.length) {
if (chars[startIndex] == '1') {
endIndex++;
}
result.append(codes.get(Integer.valueOf(new String(chars, startIndex, endIndex-startIndex+1))));
startIndex = endIndex + 1;
endIndex = startIndex + 1;
}
}
}
Code: Select all
got acc
Code: Select all
aefd
z?.: ;e
001201
abc
67798999
Have a Nice Day !
! , . : ; ?
!,.:;?
abcd
001998979
Code: Select all
00120110179
1019523856436221
fd
998979
cbaL
332312179862310199501872379231018117927
362395238523642344233323
369585644433
001998979
abcd
Code: Select all
00120110179
1019523856436221
fd
998979
cbaL
332312179862310199501872379231018117927
362395238523642344233323
369585644433
001998979
abcd
Code: Select all
aefd
z?.: ;e
001201
abc
67798999
Have a Nice Day !
! , . : ; ?
!,.:;?
abcd
001998979