ACM Timus 1496. Spammer

Problem Link: 1496. Spammer

 

 


#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    int i,j,k,o,p;

    scanf("%d",&n);

    string s[n];

    for(i=0;i<n;i++)
        cin >> s[i];

    string x[n],y;

    p=0;

    for(i=0;i<n;i++){

        if(i==n-1)
            j=i;
        else
            j=i+1;

        k=0;

        for(;j<n;j++){

            if(s[i].compare(s[j])==0){
                k=1;
                break;
            }
        }
        if(k=1){
            y=s[i];

            o=0;

            for(j=0;j<i;j++){
                if(y.compare(x[j])==0)
                    o=1;
            }

            if(o==0){

                x[p]=y;
                p++;
            }
        }

    }

    sort(x,x+p);

    for(i=0;i<p;i++){

        o=0;

        for(j=0;j<n;j++){

            if(x[i].compare(s[j])==0){
                o++;
                if(o>1){
                    cout << x[i] << endl;
                    break;
                    }

            }
        }
    }

    return 0;
}

Advertisements

[ACM Timus] 1083. Factorials!!! [c]

Problem link: 1083. Factorials!!!

 
http://acm.timus.ru/problem.aspx?space=1&num=1083
 
[c]
#include<stdio.h>
void factorial(int a, int j);
int main()
{
int a,i,j=0;
char b[21];
scanf("%d %s",&a,b);
for(i=0;i<20;i++){
if(b[i]==’!’)
j++;
else if(b[i]==’\0’)
break;
}
factorial(a,j);

return 0;
}
void factorial(int a, int j){
int k,m;
m=a;
for(k=1;;k++){
if((m-k*j)<=0)
break;
a=a*(m-k*j);
}

printf("%dn",a);
}

[/c]

[ACM Timus] 1068. Sum [C]

Problem Link: 1068. Sum

 
[c]
#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d",&a);
if(a>0)
b=a*(a+1)/2;
else{
d=0;
for(c=1;c>=a;c–){
d=d+c;
}
b=d;
}
printf("%d",b);
return 0;
}
[/c]