UVA String Processing Problem Solution

  string-processing-problem-solutionUVa string processing problem solution  are related to string.String processing problem are  like:Cipher,Encode,Encrypt,Decode, Decrypt,Frequency Counting, Input Parsing,Output Formatting,String Comparison,String Matching,String Processing with Dynamic Programming.

Actually some  String Processing problems are easy and can be solved by previous knowledge.  But be careful about time, space and special criteria when solving them.

UVA String Processing Problem Solution :

UVa: 488(Triangle Wave)

#include<stdio.h>
#include<assert.h>
void main()
{

int i,j,k,l,n,m,kase,p;
scanf("%d",&kase);
for(p=1;p<=kase;p++)
{
scanf("%d",&m);
scanf("%d",&n);
for(l=1;l<=n;l++)
{
for(i=1;i<=m+1;i++)
{
if(i<=m)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
else
{
for(k=m-1;k>=1;k--)
{
for(j=1;j<=k;j++)
printf("%d",k);
printf("\n");
}
}
}
if(l<n)
printf("\n");
}
if(p!=kase)
printf("\n");
}
}

UVa: 10252(Common Permutation)

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

#define MIN(a,b) (a>b?b:a)
#define MAXN 1001
char A[MAXN], B[MAXN];
int FA[300], FB[MAXN];

int com(const void *a, const void *b) {
return *(char *)a - *(char *)b;
}

void Cal() {
int i, m, j;
qsort(A,strlen(A),sizeof(char),com);
qsort(B,strlen(B),sizeof(char),com);
for(i = 0; A[i]; i++){
m = A[i];
FA[m] ++;
}
for(i = 0; B[i]; i++){
m = B[i];
FB[m] ++;
}
for(i = 97; i<=122; i++) {
if(FA[i] && FB[i]) {
m = MIN(FA[i], FB[i]);
for(j = 0; j<m; j++)
printf("%c",i);
}
}
printf("\n");
}

void main() {
while(gets(A)) {
gets(B);
for(int i = 97; i<= 125; i++)
FA[i] = FB[i] = 0;
Cal();
}
}

UVa: 10298(Power Strings)

#include <stdio.h>
#include<string.h>
char s[1000000];

main(){
int i,j,k,m,n;
while (gets(s) && strcmp(s,".")) {
m = n = strlen(s);
for (i=2;i<=n;i++) {
while (n%i == 0) {
n /= i;
for (j=0;j<m-m/i && s[j] == s[j+m/i];j++);
if (j == m-m/i) m /= i;
}
}
printf("%d\n",strlen(s)/m);
}
}

UVa:10878(Decode the tape)

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

char str[100];

int F() {
int i, d = 1, sum = 0;
for(i = 9; i>1; i--) {
if(str[i] != ' ' && str[i] != 'o') continue;
if(str[i] == 'o')
sum += d;
d *= 2;

}
return sum;
}
void Cal() {
int d;
gets(str);
while(strcmp(str,"___________")) {
d = F();
printf("%c",d);
gets(str);
}
}

void main() {

gets(str);
Cal();
}

Note:More interested things are waiting to publish..Stay connected to us..

——————-:Thank you:—————–

Related Post or You may felt Interest:

  1. Introduction of acm ICPC & UVa Online Judge
  2. Programming Sites & Resources
  3. Introduction & Ad Hoc Problems Solution
  4. Data Structures & Libraries problem Solution
  5. UVa Mathematics Problem Solution
  6. Computational Geometry Problem Solution
  7. Graphs Problem Solution
  8. Other Problem Solution

Like Our Facebook Page To Get Update