# Data Structures and Libraries problem Solution

Data Structures and Libraries Problems  are more interesting to solve.These problem are are not easy but solvable.Some of the problems type Like: Basic Data Structures, Sorting-related problems, Static array, vector, bitset, Direct Addressing Table,STL stack,queue,STL priority_queue are the Data Structures problem With Built-in Libraries and also solvable.

Generally most Data Structures and Libraries Problems  are easy and can be solved by previous

knowledge & with help of internet.  But be careful about time, space and special criteria when solving them.Here are the some data structures and libraries problem given, UVa-299 -Train Swapping,UVa-146-ID Codes, UVa-673-Parentheses Balance,UVa-11340-Newspaper.

# UVa: 146 – ID Codes

```#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main () {
char c[65];
while (scanf("%s",c)==1 && c[0]!='#') {
if (next_permutation (c,c+strlen(c)))
printf("%s\n",c);
else
printf("No Successor\n");
}
return 0;
}```

# UVa:  299 – Train Swapping

```#include <stdio.h>

int main (){
long int n,a[55],x,c,i,j,t;

scanf("%ld",&n);

while (n--){

scanf("%ld",&x);
for (i=1; i<=x; i++)
scanf("%ld",&a[i]);

c=0;
for (i=1; i<=x; i++)
for (j=i+1; j<=x; j++)
if (a[i]>a[j]){
t=a [i];
a[i]=a[j];
a[j]=t;
c++;
}

printf("Optimal train swapping takes %ld swaps.\n", c);
}
return 0;
}```

# UVa:  673 – Parentheses Balance

```#include<stdio.h>
#include<string.h>
int main(){
int i,n,top;
char a[150],b[150],ch;
scanf("%d%c",&n,&ch);
while(n-->0){
top=0;
gets(a);
for(i=0;i<strlen(a);i++){
if(a[i]=='(')
b[top++]=a[i];
else if(a[i]=='[')
b[top++]=a[i];
else if(a[i]==')'&&top!=0&&b[top-1]=='(')
top--;
else if(a[i]==']'&&top!=0&&b[top-1]=='[')
top--;
else
break;
}

if(top==0 && i==strlen(a))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}```

# UVa:  11340 – Newspaper

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

int n,p,v;
unsigned long long int sum;
char c,k,po[10001];

int main()
{

scanf("%ld",&n);

while(n--)
{
sum=0;
int ch[300]={0};
scanf("%d%c",&p,&c);

while(p--)
{
scanf("%c %d%c",&k,&v,&c);
ch[k]=v;
}

scanf("%d%c",&p,&c);
while(p--)
{
gets(po);
for(v=0; v<strlen(po); v++)
if(ch[po[v]]) sum+=ch[po[v]];
}
printf("%.2f\$\n",sum/100.00);
}

return 0;
}```

## Related Post or You may Like:

Updated: October 15, 2014 — 1:34 am