Pages

Thursday, October 22, 2009

UVA Problem#11530


Question:
http://uva.onlinejudge.org/external/115/11530.html

Solution:
int main(){
.....
..... 

if(s[j]=='a' || s[j]=='d' || s[j]=='g' || s[j]=='j' || s[j]=='m' 
|| s[j]=='p' || s[j]=='t' || s[j]=='w' || s[j]==' '){
c += 1;
}else if(s[j]=='b' || s[j]=='e' || s[j]=='h' || s[j]=='k' 
|| s[j]=='n' || s[j]=='q' || s[j]=='u' || s[j]=='x'){
c += 2;
}else if(s[j]=='c' || s[j]=='f' || s[j]=='i' || s[j]=='l' || 
s[j]=='o' || s[j]=='r' || s[j]=='v' || s[j]=='y'){
c += 3;
}else{
c += 4;
}
....
.... 
 
}


UVA Problem#10222

Question:

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

void pri(char c){
if(c == ']'){
printf("p");
}else if(c == '['){
printf("o");
}else if(c == 'p' || c == 'P'){
printf("i");
}else if(c == 'o' || c == 'O'){
printf("u");
}else if(c == 'i' || c == 'I'){
printf("y");
}else if(c == 'u' || c == 'U'){
printf("t");
}else if(c == 'y' || c == 'Y'){
printf("r");
}else if(c == 't' || c == 'T'){
printf("e");
}else if(c == 'r' || c == 'R'){
printf("w");
}else if(c == 'e' || c == 'E'){
printf("q");
}else if(c == '\''){
printf("l");
}else if(c == ';'){
printf("k");
}else if(c == 'l' || c == 'L'){
printf("j");
}else if(c == 'k' || c == 'K'){
printf("h");
}else if(c == 'j' || c == 'J'){
printf("g");
}else if(c == 'h' || c == 'H'){
printf("f");
}else if(c == 'g' || c == 'G'){
printf("d");
}else if(c == 'f' || c == 'F'){
printf("s");
}else if(c == 'd' || c == 'D'){
printf("a");
}else if(c == '.'){
printf("m");
}else if(c == ','){
printf("n");
}else if(c == 'm' || c == 'M'){
printf("b");
}else if(c == 'n' || c == 'N'){
printf("v");
}else if(c == 'b' || c == 'B'){
printf("c");
}else if(c == 'v' || c == 'V'){
printf("x");
}else if(c == 'c' || c == 'C'){
printf("z");
}else if(c == 's' || c == 'S'){
printf("]");
}else if(c == 'a' || c == 'A'){
printf("[");
}else if(c == 'x' || c == 'X'){
printf("\\");
}else if(c == 'z' || c == 'Z'){
printf("\'");
}
}

UVA Problem#10018

Question:

Solutions :
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

char s1[100], s[100], s2[100];

void add(char f[], char s[], char r[]){
int lf, ls, d=0, i, j=0, c=0, sum;
lf=strlen(f); ls=strlen(s);
reverse(f, f+lf); reverse(s, s+ls);
if(lf>=ls){
d=lf-ls;
for(i=0; i<ls; i++){
sum = f[i]+s[i]-96+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
for(i=ls; i<lf; i++){
sum = f[i]-48+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
if(c!=0){
sum = c%10;
r[j++] = sum+48;
if(c>9)r[j++] = (c/10)+48;
}
r[j] = '\0';
lf = strlen(r);
reverse(r, r+lf);
}else{
d=lf-ls;
for(i=0; i<lf; i++){
sum = f[i]+s[i]-96+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
for(i=lf; i<ls; i++){
sum = s[i]-48+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
if(c!=0){
sum = c%10;
r[j++] = sum+48;
if(c>9)r[j++] = (c/10)+48;
}
r[j] = '\0';
lf = strlen(r);
reverse(r, r+lf);
}
}

UVA Problem#543

Question:

Solutions :
#include<stdio.h>
#include<math.h>

int prime(int n){
int i, c=1, j=int(sqrt(n));
for(i=2; i<=j; i++){
if(n%i==0){
c = 0;
break;
}
}
return c;
}

UVA Problem#458

Question:

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

char s[1000000];

int main(){
int i, l, c;
while(gets(s) != NULL){
l = strlen(s);
for(i=0; i<l; i++){
c = s[i]-7;
printf("%c", c);
}
printf("\n");
}
return 0;
}

UVA Problem#424

Question:

Solution: 
char f[100000], s[100000], r[100000]; 
void add(char f[], char s[], char r[]){ 
int lf, ls, d, i, j=0, c=0, sum; lf=strlen(f);
ls=strlen(s); 
reverse(f, f+lf); 
reverse(s, s+ls); 

UVA Problem#382

Question:

Solution: 
void perfection(int n){
int i , sum=0, m=n/2; 
for(i=1; i<=m; i++){ 
if(n%i==0)
sum += i; 
}
if(n>sum){ 
printf("DEFICIENT\n"); 
}
else if(n<sum){ 
printf("ABUNDANT\n"); 
}
else if(n == sum){
printf("PERFECT\n"); 
}
  int main(){
....
.... 
}