Uva 12543 – Longest Word

Problem:- http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3988

Solution :-

#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include <queue>
#include <vector>
#include<algorithm>
using namespace std;
#define ll long long
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
int main()
{
    char s[1000005],a[1000005];
        int max=1;
    while(sc(“%s”,s))
    {
        if(!strcmp(s,”E-N-D”))
        break;
        int l=strlen(s);
        int c=0;
        for(int i=0;i<l;i++)
        {
            if(s[i]>=’a’&&s[i]<=’z’||s[i]>=’A’&&s[i]<=’Z’||s[i]==’-‘)
            continue;
            else
            c++;
        }
        l=l-c;
        if(max<l){
            max=l;
            strcpy(a,s);
        }
    }
    int l=strlen(a);
    for(int i=0;i<l;i++)
    {
    if(a[i]>=’A’&&a[i]<=’Z’)
    pf(“%c”,a[i]+32);
    else if(a[i]>=’a’&&a[i]<=’z’||a[i]==’-‘)
    pf(“%c”,a[i]);
    }
    pf(“n”);
    return 0;
}
At First you can try to solve this problem if you can’t than see this code & find what’s your problem . If you copy paste this code you could not improve yourself in programming .

Posted by Shipu Ahamed

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.