little joey wrote:Hi hi.
We were writing our postings at the same time! Julien and I said exactly the same thing.
![:lol:](./images/smilies/icon_lol.gif)
![:wink:](./images/smilies/icon_wink.gif)
Moderator: Board moderators
Code: Select all
1. Length of longest match: 2
2. Blank!
3. Length of longest match: 0
4. Length of longest match: 0
5. Length of longest match: 0
Code: Select all
/*
* ACM Contest training
* Ion Lamasanu , July 2004
*
* Bangla numbers: 10101
*/
#include <stdio.h>
#include <math.h>
char *name[] = {
"",
"shata",
"hajar",
"lakh",
"kuti", /***/
"shata",
"hajar",
"lakh",
"kuti", /***/
"shata",
"hajar" };
double number[] = {
1e0,
1e2,
1e3,
1e5,
1e7, /***/
1e9,
1e10,
1e12,
1e14, /***/
1e16,
1e17 };
double count[11];
double fdiv(double d, double x);
/* double fmod(double d, double x); EXISTA */
void calc(double N, int ind);
int main(void)
{
int t=0;
double N;
while( scanf("%lf", &N) != EOF )
{
printf("%4d.", ++t);
if(N == 0.00)
puts(" 0");
else
{
calc(N, 0);
puts("");
}
}
return 0;
}
double fdiv(double d, double x)
{
double r = fmod(d,x);
return (d-r)/x;
}
void calc(double N, int ind)
{
if(N > 0.00)
{
double r = fmod(N, number[ind+1]);
N -= r;
r = fdiv(r, number[ind]);
count[ind] = r;
calc(N, ind+1); /** calc */
printf(" %.0lf %s", r, name[ind]); /** print */
}
}
Code: Select all
/*
* ACM Contest training
* Ion Lamasanu , iulie 2004
*
* Longest match: 10100
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char s1[1010], s2[1010], *words1[1000], *words2[1000];
int n1, n2; /*** number of words */
int wordSrch(char s[], char *words[]);
void wordPrint(int n, char *words[]);
int longestMatch(void);
void init(void);
int main(void)
{
int t = 0;
fflush(stdin);
while( 1 )
{
init();
if( fgets(s1,1005,stdin)== NULL )
break;
fgets(s2,1005,stdin);
printf("%2d. ", ++t);
if( *s1==0 || *s1=='\r' || *s1=='\n' || *s2==0 || *s2=='\r' || *s2=='\n' )
puts("Blank!");
else
{
n1 = wordSrch(s1, words1);
n2 = wordSrch(s2, words2);
/* wordPrint(n1, words1);
wordPrint(n2, words2); */
printf("Length of longest match: %d\n", longestMatch() );
}
}
return 0;
}
int wordSrch(char s[], char *words[])
{
int n, i;
n = i = 0;
while(i < 1010)
if( isalpha(*s) )
{
words[n] = s;
n++;
while( isalpha(*s) && i<1010 )
s++, i++;
}
else {
*s = 0;
s++;
i++;
}
return n;
}
void wordPrint(int n, char *words[])
{
int i;
printf("{ ");
for(i=0; i<n; i++)
printf("%s ", words[i]);
puts("}");
}
int longestMatch(void)
{
int i, j, nr=0, t, a, b;
/*
for(i=0; i<1010; i++)
{
s1[i] = toupper(s1[i]);
s2[i] = toupper(s2[i]);
} */
for(i=0; i<n1; i++)
{
for(j=0; j<n2; j++)
if( strcmp(words1[i],words2[j])==0 )
{
a = i;
b = j;
t = 0;
while( a<n1 && b<n2 )
{
if( strcmp(words1[a],words2[b])==0 )
{
a++;
b++;
t++;
}
else
break;
}
if(t > nr) nr = t;
}
}
return nr;
}
void init(void)
{
int i;
for(i=0; i<1010; i++)
s1[i] = s2[i] = 0;
}
For each case of input, you have to output a line starting with the case number right justified in a field width of two