#include<bits/stdc++.h> using namespace std; int main(){ int n,m=0,k=0,l; size_t p; string a,b; while(getline(cin,a)){ if(a[0] == '+') m++; else if(a[0] == '-') m--; else { k+=m*(a.size()-a.find(':')-1); } } cout << k <<endl; return 0 ; }
Tuesday, August 30, 2016
Codeforces-A. Chat Server's Outgoing Traffic
Codeforces[div.2-659]-A. Round House
#include <stdio.h> #include <math.h> int main() { int n, a, b, r, d; while(scanf("%d%d%d", &n, &a, &b)==3) { d = (a+b)%n; if(d<0)d+=n; if(d==0)d=n; printf("%d\n",d); } return 0; }
Codeforces[div.2-706]-A. Beru-taxi
#include <bits/stdc++.h> using namespace std; int main() { int n,p,i,j,lo=0,q,a[100001],t=0,a1,b,x,z,y; double k ,l = 1e99; cin >> a1>>b>>n; for(i=1;i<=n;i++){ cin >>x>>y>>z; k = hypot(x - a1 + 0., y - b + 0.) / z; l = min(l,k); } printf("%.10f\n",l); return 0; }
Codeforces[div.2-706B]-B. Interesting drink
#include <bits/stdc++.h> using namespace std; int main() { int n,p,i,j,k,lo=0,q,t=0; long int q1; cin >> n; vector<int>a(n); for(i=0;i<n;i++)cin >>a[i]; sort(a.begin(),a.end()); cin >> q; for(i=0;i<q;i++){ cin >>q1; k = upper_bound(a.begin(),a.end(),q1)-a.begin(); cout<<k<<endl; } return 0; }
Codeforces-(dev 709A)-A. Juicer
#include<stdio.h> #include<math.h> int main() { int i,n,b,c = 0,d,sum = 0,a[100001]; scanf("%d %d %d",&n,&b,&d); for(i = 0 ; i < n ; i++) { scanf("%d",&a[i]); if(a[i] <= b){ sum += a[i];} if(sum>d){c++;sum = 0;} } printf("%d\n",c); return 0; }
Monday, August 29, 2016
hackerrank- Minimum Distances locked(https://www.hackerrank.com/contests/june-world-codesprint/challenges/minimum-distances)
#include <bits/stdc++.h>
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
Sunday, August 28, 2016
uri- 2144 - Bodybuilder
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
double W1, W2, R, acumulacao=0.0;
int qtd=0;
while(cin >> W1 >> W2 >>R ){
double esq, dir;
double media;
if(qtd !=0)
cout<<endl;
if(W1+W2+R == 0)
break;
esq = W1*(1+ R/30);
dir = W2*(1+ R/30);
media = (esq+dir)/2;
acumulacao+=media;
qtd++;
if(media>=1 && media < 13){
cout << "Nao vai da nao";
}
if(media>=13 && media <14){
cout << "E 13";
}
if(media>=14 && media <40){
cout << "Bora, hora do show! BIIR!" ;
}
if(media>=40 && media <=60){
cout << "Ta saindo da jaula o monstro!" ;
}
if(media>60){
cout << "AQUI E BODYBUILDER!!" ;
}
}
if((acumulacao/qtd)>40){
cout<<"\n";
printf("Aqui nois constroi fibra rapaz! Nao e agua com musculo!\n");
}
return 0;
}
#include <stdio.h>
using namespace std;
int main(){
double W1, W2, R, acumulacao=0.0;
int qtd=0;
while(cin >> W1 >> W2 >>R ){
double esq, dir;
double media;
if(qtd !=0)
cout<<endl;
if(W1+W2+R == 0)
break;
esq = W1*(1+ R/30);
dir = W2*(1+ R/30);
media = (esq+dir)/2;
acumulacao+=media;
qtd++;
if(media>=1 && media < 13){
cout << "Nao vai da nao";
}
if(media>=13 && media <14){
cout << "E 13";
}
if(media>=14 && media <40){
cout << "Bora, hora do show! BIIR!" ;
}
if(media>=40 && media <=60){
cout << "Ta saindo da jaula o monstro!" ;
}
if(media>60){
cout << "AQUI E BODYBUILDER!!" ;
}
}
if((acumulacao/qtd)>40){
cout<<"\n";
printf("Aqui nois constroi fibra rapaz! Nao e agua com musculo!\n");
}
return 0;
}
uri- 1940 - Strategy Game
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,n1,c=0,c1,c2,max,pos,bar[501],arr[250001],j;
cin >> n >> n1 ;
max = pos = 0;
for(i=1;i<=n*n1;i++){
cin >> arr[i];
}
for(i=1;i<=n;i++){
c=0;
for(j=i;j<=n1*n;j+=(n)){
c += arr[j];
}
if(max<=c){
max = c;
pos = i;
}
}
cout << pos <<endl;
return 0;
}
using namespace std;
int main()
{
int n,i,n1,c=0,c1,c2,max,pos,bar[501],arr[250001],j;
cin >> n >> n1 ;
max = pos = 0;
for(i=1;i<=n*n1;i++){
cin >> arr[i];
}
for(i=1;i<=n;i++){
c=0;
for(j=i;j<=n1*n;j+=(n)){
c += arr[j];
}
if(max<=c){
max = c;
pos = i;
}
}
cout << pos <<endl;
return 0;
}
uri- 1893 - Moon Phases
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b1,b2;
cin >> b1 >>b2 ;
if(b1>b2){
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"minguante"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}else{
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"crescente"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}
return 0;
}
using namespace std;
int main() {
int a,b1,b2;
cin >> b1 >>b2 ;
if(b1>b2){
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"minguante"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}else{
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"crescente"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}
return 0;
}
uri- 1595 - Humm.. Run or Walk.. That's the Question
#include <bits/stdc++.h>
using namespace std;
int cmp(const void * a,const void * b){ return (*(int*)a - *(int*)b);}
int main() {
int ar[100001];
int t,n,s,c,r;
double res;
cin >> n ;
while(n--){
res = 0.0 ;
cin >>s>>c>>r;
for(int i = 0; i<s ; i++) cin >>ar[i];
qsort(ar,s,sizeof(int),cmp);
if(c!=0)
for(int i = 0; i<c;i++) res += 1.0/((double)ar[i]*1.0 + (double)r*1.0);
for(int i = c; i<s;i++) res += 1.0/((double)ar[i]*1.0);
printf("%.2lf\n",res);
}
return 0;
}
using namespace std;
int cmp(const void * a,const void * b){ return (*(int*)a - *(int*)b);}
int main() {
int ar[100001];
int t,n,s,c,r;
double res;
cin >> n ;
while(n--){
res = 0.0 ;
cin >>s>>c>>r;
for(int i = 0; i<s ; i++) cin >>ar[i];
qsort(ar,s,sizeof(int),cmp);
if(c!=0)
for(int i = 0; i<c;i++) res += 1.0/((double)ar[i]*1.0 + (double)r*1.0);
for(int i = c; i<s;i++) res += 1.0/((double)ar[i]*1.0);
printf("%.2lf\n",res);
}
return 0;
}
uri- 1451 - Broken Keyboard
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
list<char>s1;
list<char>::iterator it;
while(cin >> a){
s1.clear();
it = s1.begin();
for(int i = 0; i<a.size();i++){
if(a[i] == ']') {
it = s1.end();
} else if(a[i] == '[') {
it = s1.begin();
}else {
s1.insert(it, a[i]);
}
}
for(it = s1.begin(); it != s1.end(); it++)
cout << *it;
cout << '\n';
}
return 0;
}
using namespace std;
int main() {
string a;
list<char>s1;
list<char>::iterator it;
while(cin >> a){
s1.clear();
it = s1.begin();
for(int i = 0; i<a.size();i++){
if(a[i] == ']') {
it = s1.end();
} else if(a[i] == '[') {
it = s1.begin();
}else {
s1.insert(it, a[i]);
}
}
for(it = s1.begin(); it != s1.end(); it++)
cout << *it;
cout << '\n';
}
return 0;
}
uri- 1383 - Sudoku
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, i, j, k, sum = 285, cnt = 0;
int a[9][9];
string s = "";
cin >> n;
while(n--) {
for(i = 0; i < 9; i++)
for(j = 0; j < 9; j++)
cin >> a[i][j];
int sl[9], sc[9], sm[3][3];
for (i = 0; i < 9; i++)
sl[i] = sc[i] = sm[i/3][i%3] = 0;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
k = a[i][j];
k *= k;
sl[i] += k;
sc[j] += k;
sm[i/3][j/3] += k;
if (i == 8 && sc[j] != 285)
break;
}
if (sl[i] != 285)
break;
}
// if(s == "")
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if (sm[i][j] != 285)
s = "NAO";
if(s == "")
s = "SIM";
cnt++;
cout << "Instancia " << cnt << endl << s << endl << endl;
s = "";
}
return 0;
}
using namespace std;
int main(int argc, char const *argv[]) {
int n, i, j, k, sum = 285, cnt = 0;
int a[9][9];
string s = "";
cin >> n;
while(n--) {
for(i = 0; i < 9; i++)
for(j = 0; j < 9; j++)
cin >> a[i][j];
int sl[9], sc[9], sm[3][3];
for (i = 0; i < 9; i++)
sl[i] = sc[i] = sm[i/3][i%3] = 0;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
k = a[i][j];
k *= k;
sl[i] += k;
sc[j] += k;
sm[i/3][j/3] += k;
if (i == 8 && sc[j] != 285)
break;
}
if (sl[i] != 285)
break;
}
// if(s == "")
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if (sm[i][j] != 285)
s = "NAO";
if(s == "")
s = "SIM";
cnt++;
cout << "Instancia " << cnt << endl << s << endl << endl;
s = "";
}
return 0;
}
uri- 1033 - How Many Calls?
#include <bits/stdc++.h>
using namespace std;
typedef long long Nu;
int bigmod(Nu n, const int M)
{
if ( n <= 0 ) return 0;
Nu a, b, c, d, r;
a = 1, b = 0 , c = 0, d = 1;
--n;
while ( n > 0 )
{
if ( n&1 )
{
r = ( (d*b) + (c*a) )%M;
b = ( d*(b+a) + (c*b) )%M;
a = r;
}
r = ( c*c + d*d )%M;
d = ( d * (2*c + d) )%M;
c = r;
n = n/2;
}
return (a + b)%M;
}
int main()
{
Nu k;
int g, h, re = 0;
while (cin >> k >> g && (k || g) )
{
h = ( (2 * bigmod(k+1, g)) - 1 + g ) % g;
printf("Case %d: %lld %d %d\n", ++re, k, g, h);
}
return 0;
}
using namespace std;
typedef long long Nu;
int bigmod(Nu n, const int M)
{
if ( n <= 0 ) return 0;
Nu a, b, c, d, r;
a = 1, b = 0 , c = 0, d = 1;
--n;
while ( n > 0 )
{
if ( n&1 )
{
r = ( (d*b) + (c*a) )%M;
b = ( d*(b+a) + (c*b) )%M;
a = r;
}
r = ( c*c + d*d )%M;
d = ( d * (2*c + d) )%M;
c = r;
n = n/2;
}
return (a + b)%M;
}
int main()
{
Nu k;
int g, h, re = 0;
while (cin >> k >> g && (k || g) )
{
h = ( (2 * bigmod(k+1, g)) - 1 + g ) % g;
printf("Case %d: %lld %d %d\n", ++re, k, g, h);
}
return 0;
}
uri- 2172 - Event
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long r;
while ((cin >> n >> r) && (n&&r)!=0){
cout<<n*r<<endl;
}
return 0;
}
using namespace std;
int main() {
int n;
long r;
while ((cin >> n >> r) && (n&&r)!=0){
cout<<n*r<<endl;
}
return 0;
}
uri- 2187 - Bits Exchanged
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i,j=0,k,l,m,n;
while(cin>>n && n){
i = l = k = m = 0;
j++;
i = n/50;
k = (n - i*50)/10;
l = (n - (i*50+k*10))/5;
m = (n - (i*50+k*10+l*5))/1;
cout<<"Teste "<<j<<"\n"<<i <<" "<<k<<" "<<l <<" "<<m<<endl<<endl;
}
return 0 ;
}
using namespace std;
int main()
{
int i,j=0,k,l,m,n;
while(cin>>n && n){
i = l = k = m = 0;
j++;
i = n/50;
k = (n - i*50)/10;
l = (n - (i*50+k*10))/5;
m = (n - (i*50+k*10+l*5))/1;
cout<<"Teste "<<j<<"\n"<<i <<" "<<k<<" "<<l <<" "<<m<<endl<<endl;
}
return 0 ;
}
uri- 2171 - Sharing with Fink
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,j=0;
long r;
while (cin >>r && r!=0){
j=0;
for(int i = 1;j+i<=r;i++){
j +=i;
}
cout<<j<<" "<<r - j<<endl;
}
return 0;
}
using namespace std;
int main() {
int n,j=0;
long r;
while (cin >>r && r!=0){
j=0;
for(int i = 1;j+i<=r;i++){
j +=i;
}
cout<<j<<" "<<r - j<<endl;
}
return 0;
}
uri- 2174 - Pomekon Collection
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> n;
set<string>ar;
while(n--){
cin >> a;
ar.insert(a);
}
printf("Falta(m) %d pomekon(s).\n",151-ar.size());
ar.clear();
return 0 ;
}
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> n;
set<string>ar;
while(n--){
cin >> a;
ar.insert(a);
}
printf("Falta(m) %d pomekon(s).\n",151-ar.size());
ar.clear();
return 0 ;
}
uri- 2175 - What is the Fastest?
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,i,k,j,l;
string a;
cin>> n >> i >> k;
l = min(n,min(i,k));
if(n==l && (n != i && n!=k))cout<<"Otavio\n";
else if(i==l && (n != i && i!=k))cout<<"Bruno\n";
else if(k==l && (k != i && n!=k))cout<<"Ian\n";
else cout<<"Empate\n";
return 0 ;
}
using namespace std;
int main()
{
double n,i,k,j,l;
string a;
cin>> n >> i >> k;
l = min(n,min(i,k));
if(n==l && (n != i && n!=k))cout<<"Otavio\n";
else if(i==l && (n != i && i!=k))cout<<"Bruno\n";
else if(k==l && (k != i && n!=k))cout<<"Ian\n";
else cout<<"Empate\n";
return 0 ;
}
uri- 2176 - Parity
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> a;
for(int p = 0; p<a.size();p++){
if(a[p]=='1')k++;
}
if(k%2==0) cout<<a<<'0'<<endl;
else cout<<a<<'1'<<endl;
return 0 ;
}
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> a;
for(int p = 0; p<a.size();p++){
if(a[p]=='1')k++;
}
if(k%2==0) cout<<a<<'0'<<endl;
else cout<<a<<'1'<<endl;
return 0 ;
}
uri- 1028 - Collectable Cards
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,n;
scanf("%d",&n);
while(n--){
scanf("%d %d",&a,&b);
printf("%d\n",__gcd(a,b));
}
return 0;
}
using namespace std;
int main()
{
int a,b,c,n;
scanf("%d",&n);
while(n--){
scanf("%d %d",&a,&b);
printf("%d\n",__gcd(a,b));
}
return 0;
}
uri-1212 - Primary Arithmetic
#include<stdio.h>
int main()
{
long int d1, d2,c, count,m1,m2,s,length,b;
while(scanf("%ld %ld",&d1, &d2))
{
if(d1==0 && d2==0)
break;
if(d1>d2)
b=d1;
else
b=d2;
length=0;
while(b!=0)
{
b/=10;
length++;
}
count=0;
c=0;
while(length!=0)
{
m1=d1%10;
d1=d1/10;
m2=d2%10;
d2=d2/10;
s=m1+m2+c;
if(s>9)
{
count++;
c=s/10;
}
else
c=0;
length--;
}
if(count==0)
printf("No carry operation.\n");
else if(count==1)
printf("1 carry operation.\n");
else
printf("%ld carry operations.\n",count);
}
return 0;
}
int main()
{
long int d1, d2,c, count,m1,m2,s,length,b;
while(scanf("%ld %ld",&d1, &d2))
{
if(d1==0 && d2==0)
break;
if(d1>d2)
b=d1;
else
b=d2;
length=0;
while(b!=0)
{
b/=10;
length++;
}
count=0;
c=0;
while(length!=0)
{
m1=d1%10;
d1=d1/10;
m2=d2%10;
d2=d2/10;
s=m1+m2+c;
if(s>9)
{
count++;
c=s/10;
}
else
c=0;
length--;
}
if(count==0)
printf("No carry operation.\n");
else if(count==1)
printf("1 carry operation.\n");
else
printf("%ld carry operations.\n",count);
}
return 0;
}
uri- 1168 - LED
#include <stdio.h>
int main(){
int a, j,i;
char n[101];
long long leds;
scanf("%d", &a);
for( i = 0; i < a; i++){
scanf("%s", &n);
j = 0;
leds = 0;
while(1){
if(n[j] == '\0') break;
if(n[j] == '1') leds += 2;
if(n[j] == '2' || n[j]=='3' || n[j]=='5') leds += 5;
if(n[j] == '4') leds += 4;
if(n[j] == '6' || n[j]=='9' || n[j]=='0') leds += 6;
if(n[j] == '7') leds += 3;
if(n[j] == '8') leds += 7;
j++;
}
printf("%lld leds\n", leds);
}
return 0;
}
int main(){
int a, j,i;
char n[101];
long long leds;
scanf("%d", &a);
for( i = 0; i < a; i++){
scanf("%s", &n);
j = 0;
leds = 0;
while(1){
if(n[j] == '\0') break;
if(n[j] == '1') leds += 2;
if(n[j] == '2' || n[j]=='3' || n[j]=='5') leds += 5;
if(n[j] == '4') leds += 4;
if(n[j] == '6' || n[j]=='9' || n[j]=='0') leds += 6;
if(n[j] == '7') leds += 3;
if(n[j] == '8') leds += 7;
j++;
}
printf("%lld leds\n", leds);
}
return 0;
}
uri-1566 - Height
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int array[3000000]={0};
int tc,n;
int i;
scanf("%d",&tc);
while(tc--){
scanf("%d",&n);
for(int j=0;j<n;j++){
scanf("%d",&array[j]);
}
sort(array,array+n);
for(i=0;i<n-1;i++)
printf("%d ",array[i]);
printf("%d",array[n-1]);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int array[3000000]={0};
int tc,n;
int i;
scanf("%d",&tc);
while(tc--){
scanf("%d",&n);
for(int j=0;j<n;j++){
scanf("%d",&array[j]);
}
sort(array,array+n);
for(i=0;i<n-1;i++)
printf("%d ",array[i]);
printf("%d",array[n-1]);
printf("\n");
}
return 0;
}
uri- 1866 - Bill
#include<stdio.h>
int main()
{
int i,a,b;
scanf("%d",&a);
while(a--){
scanf("%d",&b);
if(b%2==0){
printf("0\n");
}
else{
printf("1\n");
}
}
return 0;
}
int main()
{
int i,a,b;
scanf("%d",&a);
while(a--){
scanf("%d",&b);
if(b%2==0){
printf("0\n");
}
else{
printf("1\n");
}
}
return 0;
}
uri-1589 - Bob Conduit
#include<stdio.h>
int main(){
int a,r1,r2;
scanf("%d",&a);
while(a--){
scanf("%d %d",&r1,&r2);
printf("%d\n",r1+r2);
}
return 0;
}
int main(){
int a,r1,r2;
scanf("%d",&a);
while(a--){
scanf("%d %d",&r1,&r2);
printf("%d\n",r1+r2);
}
return 0;
}
uri-1759 - Ho Ho Ho
#include<stdio.h>
int main()
{
int a,b;
scanf("%d",&a);
b=a-1;
while(b--){
printf("Ho ");
}
printf("Ho!\n");
return 0;
}
int main()
{
int a,b;
scanf("%d",&a);
b=a-1;
while(b--){
printf("Ho ");
}
printf("Ho!\n");
return 0;
}
uri- 1864 - Our Days Are Never Coming Back
#include<stdio.h>
//#include<string.h>
int main()
{
int i,a;
char st[34]={"LIFE IS NOT A PROBLEM TO BE SOLVED"};
scanf("%d",&a);
for(i=0;i<a;i++){
printf("%c",st[i]);
}
printf("\n");
return 0;
}
//#include<string.h>
int main()
{
int i,a;
char st[34]={"LIFE IS NOT A PROBLEM TO BE SOLVED"};
scanf("%d",&a);
for(i=0;i<a;i++){
printf("%c",st[i]);
}
printf("\n");
return 0;
}
uri-1329 - Head or Tail
#include<stdio.h>
int main()
{
int b[10001],jo,j,n,i,m;
while(scanf("%d",&n)==1){
m=0,jo=0;
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%d",&b[i]);
}
for(j=0;j<n;j++){
if(b[j]==0){
m++;
}
else{
jo++;
}
}
printf("Mary won %d times and John won %d times\n",m,jo);
}
return 0;
}
int main()
{
int b[10001],jo,j,n,i,m;
while(scanf("%d",&n)==1){
m=0,jo=0;
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%d",&b[i]);
}
for(j=0;j<n;j++){
if(b[j]==0){
m++;
}
else{
jo++;
}
}
printf("Mary won %d times and John won %d times\n",m,jo);
}
return 0;
}
uri-1564 - Brazil World Cup
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
if(n)
printf("vai ter duas!\n");
else
printf("vai ter copa!\n");
}
return 0;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
if(n)
printf("vai ter duas!\n");
else
printf("vai ter copa!\n");
}
return 0;
}
uri- 1129 - Optical Reader (by C++)
#include <iostream>
using namespace std;
int main(){
int i, n, o[5], c, r,j;
char l[] = "ABCDE";
while (cin >> n && n != 0){
while (n--){
for(j=0;j<5;j++){
cin>>o[j];
}
// cin >> o[0] >> o[1] >> o[2] >> o[3] >> o[4];
c = 0;
for (i = 0; i <= 4; i++){
if (o[i] <= 127){
r = i;
c++;
}
}
if (c != 1) cout << "*" << endl;
else cout << l[r] << endl;
}
}
return 0;
}
using namespace std;
int main(){
int i, n, o[5], c, r,j;
char l[] = "ABCDE";
while (cin >> n && n != 0){
while (n--){
for(j=0;j<5;j++){
cin>>o[j];
}
// cin >> o[0] >> o[1] >> o[2] >> o[3] >> o[4];
c = 0;
for (i = 0; i <= 4; i++){
if (o[i] <= 127){
r = i;
c++;
}
}
if (c != 1) cout << "*" << endl;
else cout << l[r] << endl;
}
}
return 0;
}
uri- 1129 - Optical Reader (by C)
#include <stdio.h>
int main(){
int a,b,c,d,e,i,n;
int t;
while(scanf("%d",&n) && n!=0){
while(n--){
t = 0;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
if(a <= 127){ t++; a = 1; } else { a = 0; }
if(b <= 127){ t++; b = 1; } else { b = 0; }
if(c <= 127){ t++; c = 1; } else { c = 0; }
if(d <= 127){ t++; d = 1; } else { d = 0; }
if(e <= 127){ t++; e = 1; } else { e = 0; }
if(t == 1){
if(a == 1) printf("A\n");
if(b == 1) printf("B\n");
if(c == 1) printf("C\n");
if(d == 1) printf("D\n");
if(e == 1) printf("E\n");
}
else{
printf("*\n");
}
}
}
return 0;
}
int main(){
int a,b,c,d,e,i,n;
int t;
while(scanf("%d",&n) && n!=0){
while(n--){
t = 0;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
if(a <= 127){ t++; a = 1; } else { a = 0; }
if(b <= 127){ t++; b = 1; } else { b = 0; }
if(c <= 127){ t++; c = 1; } else { c = 0; }
if(d <= 127){ t++; d = 1; } else { d = 0; }
if(e <= 127){ t++; e = 1; } else { e = 0; }
if(t == 1){
if(a == 1) printf("A\n");
if(b == 1) printf("B\n");
if(c == 1) printf("C\n");
if(d == 1) printf("D\n");
if(e == 1) printf("E\n");
}
else{
printf("*\n");
}
}
}
return 0;
}
uri- 1789 - The Race of Slugs
#include<stdio.h>
int main()
{
int i,j,b,c,large,l=0;
while((scanf("%d",&b))!=EOF){
l=0;
int a[b];
for(j=0;j<b;j++){
scanf("%d",&a[j]);
}
large=a[0];
for(j=1;j<b;j++){
if(large<a[j]){
large=a[j];
}
}
if(large>=20){l=3;}
else if(large>=10 && large<20){l=2;}
else if(large<10){l=1;}
printf("%d\n",l);
}
return 0;
}
int main()
{
int i,j,b,c,large,l=0;
while((scanf("%d",&b))!=EOF){
l=0;
int a[b];
for(j=0;j<b;j++){
scanf("%d",&a[j]);
}
large=a[0];
for(j=1;j<b;j++){
if(large<a[j]){
large=a[j];
}
}
if(large>=20){l=3;}
else if(large>=10 && large<20){l=2;}
else if(large<10){l=1;}
printf("%d\n",l);
}
return 0;
}
uri- 1179 - Array Fill IV
#include<stdio.h>
int main()
{
int i,p[5],im[5],par=0,imp=0,a,j;
while(scanf("%d",&a)==1){
if(a%2==0){
p[par]=a;
par++;
}
else{
im[imp]=a;
imp++;
}
if(par==5){
for (j = 0; j <= 4; j++){
printf("par[%d] = %d\n",j,p[j]);
p[j]='\0';
}
par=0;
}
if(imp==5){
for (j = 0; j <= 4; j++){
printf("impar[%d] = %d\n",j,im[j]);
im[j]='\0';
}
imp=0;
}
}
for (j = 0; j <= 4; j++){
if (im[j] == '\0')
break;
printf("impar[%d] = %d\n", j, im[j]);
}
for (j = 0; j <= 4; j++){
if (p[j] == '\0')
break;
printf("par[%d] = %d\n", j, p[j]);
}
return 0;
}
int main()
{
int i,p[5],im[5],par=0,imp=0,a,j;
while(scanf("%d",&a)==1){
if(a%2==0){
p[par]=a;
par++;
}
else{
im[imp]=a;
imp++;
}
if(par==5){
for (j = 0; j <= 4; j++){
printf("par[%d] = %d\n",j,p[j]);
p[j]='\0';
}
par=0;
}
if(imp==5){
for (j = 0; j <= 4; j++){
printf("impar[%d] = %d\n",j,im[j]);
im[j]='\0';
}
imp=0;
}
}
for (j = 0; j <= 4; j++){
if (im[j] == '\0')
break;
printf("impar[%d] = %d\n", j, im[j]);
}
for (j = 0; j <= 4; j++){
if (p[j] == '\0')
break;
printf("par[%d] = %d\n", j, p[j]);
}
return 0;
}
uri- 1534 - Array 123
#include<stdio.h>
int main()
{
int n,i,j;
while(scanf("%d",&n)==1){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if((i==j && i+j==n-1 ) || i+j==n-1)
printf("2");
else if(i==j)
printf("1");
else
printf("3");
}
printf("\n");
}
}
return 0;
}
int main()
{
int n,i,j;
while(scanf("%d",&n)==1){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if((i==j && i+j==n-1 ) || i+j==n-1)
printf("2");
else if(i==j)
printf("1");
else
printf("3");
}
printf("\n");
}
}
return 0;
}
uri- 1216 - Getline One
#include <stdio.h>
int main(){
char s[101];
double d, t, n = 0.0;
while(gets(s)){
scanf("%lf", &d);
t += d;
n += 1.0;
}
printf("%.1lf\n", t / n);
return 0;
}
int main(){
char s[101];
double d, t, n = 0.0;
while(gets(s)){
scanf("%lf", &d);
t += d;
n += 1.0;
}
printf("%.1lf\n", t / n);
return 0;
}
uri- 1197 - Back to High School Physics
#include<stdio.h>
int main()
{
int a,b,s=0;
while(scanf("%d %d",&a,&b)==2){
s=a*(b*2);
printf("%d\n",s);
}
return 0;
}
int main()
{
int a,b,s=0;
while(scanf("%d %d",&a,&b)==2){
s=a*(b*2);
printf("%d\n",s);
}
return 0;
}
uri- 1198 - Hashmat the Brave Warrior
#include<stdio.h>
int main()
{
long long int a,b;
while(scanf("%lld %lld",&a,&b)==2){
if(a>b){
printf("%lld\n",a-b);
}
else{
printf("%lld\n",b-a);
}
}
return 0;
}
int main()
{
long long int a,b;
while(scanf("%lld %lld",&a,&b)==2){
if(a>b){
printf("%lld\n",a-b);
}
else{
printf("%lld\n",b-a);
}
}
return 0;
}
uri- 1221 - Fast Prime Number
#include <stdio.h>
#include <math.h>
int main(){
int n, teste,i;
long int p;
scanf("%d", &n);
while(n--){
teste = 0;
scanf("%ld", &p);
if(p<=2){
if(p == 0){
printf("Not Prime\n");
continue;
}
if(p == 1){
printf("Not Prime\n");
continue;
}
if(p == 2){
printf("Prime\n");
continue;
}
}
else{
for(i = 2; i < sqrt(p)+1; i++){
if(p%i == 0) teste++;
if(teste == 2) break;
}
if(teste >= 1) printf("Not Prime\n");
else printf("Prime\n");
}
}
return 0;
}
#include <math.h>
int main(){
int n, teste,i;
long int p;
scanf("%d", &n);
while(n--){
teste = 0;
scanf("%ld", &p);
if(p<=2){
if(p == 0){
printf("Not Prime\n");
continue;
}
if(p == 1){
printf("Not Prime\n");
continue;
}
if(p == 2){
printf("Prime\n");
continue;
}
}
else{
for(i = 2; i < sqrt(p)+1; i++){
if(p%i == 0) teste++;
if(teste == 2) break;
}
if(teste >= 1) printf("Not Prime\n");
else printf("Prime\n");
}
}
return 0;
}
uri- 1240 - Fit or Dont Fit I
#include<stdio.h>
int main()
{
int n;
long long int a,b;
scanf("%d",&n);
while(n--){
// start:
scanf("%lld %lld",&a,&b);
if(a >= b)
{
while(b != 0)
{
if(b%10 != a%10)
{
printf("nao encaixa\n");
goto finishhim;
}
a/=10;
b/=10;
}
printf("encaixa\n");
}
else
{
printf("nao encaixa\n");
}
finishhim:;
}
return 0;
}
int main()
{
int n;
long long int a,b;
scanf("%d",&n);
while(n--){
// start:
scanf("%lld %lld",&a,&b);
if(a >= b)
{
while(b != 0)
{
if(b%10 != a%10)
{
printf("nao encaixa\n");
goto finishhim;
}
a/=10;
b/=10;
}
printf("encaixa\n");
}
else
{
printf("nao encaixa\n");
}
finishhim:;
}
return 0;
}
uri-1188 - Inferior Area
#include <stdio.h>
int main(){
char o;
int i, j, x = 5;
float s = 0, n;
scanf("%c", &o);
for (i = 0; i <= 11; i++){
for (j = 0; j <= 11; j++){
scanf("%f", &n);
if (j > x && j < 11 - x)
s += n;
}
if (i > 5)
x--;
}
if (o == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s / 30);
return 0;
}
int main(){
char o;
int i, j, x = 5;
float s = 0, n;
scanf("%c", &o);
for (i = 0; i <= 11; i++){
for (j = 0; j <= 11; j++){
scanf("%f", &n);
if (j > x && j < 11 - x)
s += n;
}
if (i > 5)
x--;
}
if (o == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s / 30);
return 0;
}
uri- 1467 - Zero or One
#include<stdio.h>
int main()
{
int a,b,c;
while(scanf("%d %d %d",&a,&b,&c)!=EOF){
if((a==0 && b==0 && c==0) || (a==1 && b==1 && c==1) ){
printf("*\n");
}
else if((a==0 && b==0 && c==1) || (a==1 && b==1 && c==0)) {
printf("C\n");
}
else if((a==0 && b==1 && c==0) || (a==1 && b==0 && c==1)){
printf("B\n");
}
if((a==0 && b==1 && c==1) || (a==1 && b==0 && c==0)){
printf("A\n");
}
}
return 0;
}
int main()
{
int a,b,c;
while(scanf("%d %d %d",&a,&b,&c)!=EOF){
if((a==0 && b==0 && c==0) || (a==1 && b==1 && c==1) ){
printf("*\n");
}
else if((a==0 && b==0 && c==1) || (a==1 && b==1 && c==0)) {
printf("C\n");
}
else if((a==0 && b==1 && c==0) || (a==1 && b==0 && c==1)){
printf("B\n");
}
if((a==0 && b==1 && c==1) || (a==1 && b==0 && c==0)){
printf("A\n");
}
}
return 0;
}
uri- 1558 - Sum of Two Squares
#include<stdio.h>
#define N 10000
int len=0;
void pre_gen(int arr[]);
int main()
{
int n,i,ck;
int arr[N+1] = {0};
pre_gen(arr);
while(scanf("%d",&n)!=EOF){
if(n >= 0 && arr[n]==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
void pre_gen(int arr[])
{
int i,j,t;
for(i=0;i*i<=N;i++){
for(j=0;j*j<=N;j++){
if( (i*i)+(j*j) <= N ){
t = (i*i)+(j*j);
arr[t] = 1;
}
}
}
}
#define N 10000
int len=0;
void pre_gen(int arr[]);
int main()
{
int n,i,ck;
int arr[N+1] = {0};
pre_gen(arr);
while(scanf("%d",&n)!=EOF){
if(n >= 0 && arr[n]==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
void pre_gen(int arr[])
{
int i,j,t;
for(i=0;i*i<=N;i++){
for(j=0;j*j<=N;j++){
if( (i*i)+(j*j) <= N ){
t = (i*i)+(j*j);
arr[t] = 1;
}
}
}
}
uri- 1761 - Christmas Decorations
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c,t,angel,result;
double pi=3.141592654;
while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF){
angel=tan ( a * pi / 180.0 );
t=angel*b;
result=(t+c)*5;
printf("%.2lf\n",result);
}
return 0;
}
#include<math.h>
int main()
{
double a,b,c,t,angel,result;
double pi=3.141592654;
while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF){
angel=tan ( a * pi / 180.0 );
t=angel*b;
result=(t+c)*5;
printf("%.2lf\n",result);
}
return 0;
}
uri- 1300 - Hours and Minutes
#include<stdio.h>
int main(){
int a;
while(scanf("%d",&a)!=EOF){
if(a%6==0){
printf("Y\n");
}
else{
printf("N\n");
}
}
return 0;
}
int main(){
int a;
while(scanf("%d",&a)!=EOF){
if(a%6==0){
printf("Y\n");
}
else{
printf("N\n");
}
}
return 0;
}
uri- 1103 - Alarm Clock
#include <stdio.h>
int main(){
int h, hm, hr,m,mm,i;
for(i=0;i<10000;i++){
scanf("%d %d %d %d", &h, &m,&hm,&mm);
if(h==0 && m==0 && hm==0 && mm==0){
break;
}
if (h <= hm)
hr = (hm - h) * 60;
else
hr = (24 - (h - hm)) * 60;
if (m <= mm)
hr += mm - m;
else
hr += 60 - 60 - m + mm;
if (h == hm && m > mm)
hr = 23 * 60 + (60 - m + mm);
printf("%d\n", hr);
}
return 0;
}
int main(){
int h, hm, hr,m,mm,i;
for(i=0;i<10000;i++){
scanf("%d %d %d %d", &h, &m,&hm,&mm);
if(h==0 && m==0 && hm==0 && mm==0){
break;
}
if (h <= hm)
hr = (hm - h) * 60;
else
hr = (24 - (h - hm)) * 60;
if (m <= mm)
hr += mm - m;
else
hr += 60 - 60 - m + mm;
if (h == hm && m > mm)
hr = 23 * 60 + (60 - m + mm);
printf("%d\n", hr);
}
return 0;
}
uri- 1161 - Factorial Sum
#include <stdio.h>
int main(){
int m, n;
int i;
long long fat[21];
fat[0] = 1;
for(i = 1; i <= 20; i++){
fat[i] = fat[i-1]*i;
}
while(scanf("%d",&m)!= EOF){
scanf("%d",&n);
printf("%lld\n", fat[m] + fat[n]);
}
return 0;
}
int main(){
int m, n;
int i;
long long fat[21];
fat[0] = 1;
for(i = 1; i <= 20; i++){
fat[i] = fat[i-1]*i;
}
while(scanf("%d",&m)!= EOF){
scanf("%d",&n);
printf("%lld\n", fat[m] + fat[n]);
}
return 0;
}
uri- 1149 - Summing Consecutive Integers
#include<stdio.h>
int main()
{
int a,b,i,s=0;
scanf("%d",&a);
scanf("%d",&b);
for(i=0;i<10000;i++){
if(b<=0){
scanf("%d",&b);
}
else{
continue;
}
}
for(i=a;i<a+b;i++){
s=s+i;
}
printf("%d\n",s);
return 0;
}
int main()
{
int a,b,i,s=0;
scanf("%d",&a);
scanf("%d",&b);
for(i=0;i<10000;i++){
if(b<=0){
scanf("%d",&b);
}
else{
continue;
}
}
for(i=a;i<a+b;i++){
s=s+i;
}
printf("%d\n",s);
return 0;
}
uri- 1150 - Exceeding Z
#include<stdio.h>
int main()
{
int a,b,i,j=0,s=0;
scanf("%d",&a);
scanf("%d",&b);
for(i=0;i<10000;i++){
if(a>=b){
scanf("%d",&b);
}
else{
continue;
}
}
for(i=a;i<10000;i++){
s=s+i;
j++;
if(s>b){
break;
}
}
printf("%d\n",j);
return 0;
}
int main()
{
int a,b,i,j=0,s=0;
scanf("%d",&a);
scanf("%d",&b);
for(i=0;i<10000;i++){
if(a>=b){
scanf("%d",&b);
}
else{
continue;
}
}
for(i=a;i<10000;i++){
s=s+i;
j++;
if(s>b){
break;
}
}
printf("%d\n",j);
return 0;
}
uri- 1171 - Number Frequence
#include<stdio.h>
#include<string.h>
#define N 2001
int main()
{
int t,n,i,j;
int arr[N];
while(scanf("%d",&t)==1){
memset(arr,0,sizeof arr);
for(i=1;i<=t;i++){
scanf("%d",&n);
arr[n]++;
}
for(i=0;i<N;i++)
for(j=0;j<arr[i];j++){
if(arr[i]>0)
printf("%d aparece %d vez(es)\n",i,arr[i]);
break;
}
}
return 0;
}
#include<string.h>
#define N 2001
int main()
{
int t,n,i,j;
int arr[N];
while(scanf("%d",&t)==1){
memset(arr,0,sizeof arr);
for(i=1;i<=t;i++){
scanf("%d",&n);
arr[n]++;
}
for(i=0;i<N;i++)
for(j=0;j<arr[i];j++){
if(arr[i]>0)
printf("%d aparece %d vez(es)\n",i,arr[i]);
break;
}
}
return 0;
}
uri-1026 - To Carry or not to Carry
#include <stdio.h>
int main(){
unsigned int a, b;
while(scanf("%u %u", &a, &b) != EOF){
printf("%u\n", a ^ b);
}
return 0;
}
int main(){
unsigned int a, b;
while(scanf("%u %u", &a, &b) != EOF){
printf("%u\n", a ^ b);
}
return 0;
}
uri- 1187 - Top Area
#include <stdio.h>
int main(){
char o;
int i, j, l = 1;
double s = 0, n;
scanf("%c", &o);
for (i = 0; i <= 4; i++){
for (j = 0; j <= 11; j++){
scanf("%lf", &n);
if (j >= l && j <= 11 - l)
s += n;
}
l++;
}
if (o == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s / 30);
return 0;
}
int main(){
char o;
int i, j, l = 1;
double s = 0, n;
scanf("%c", &o);
for (i = 0; i <= 4; i++){
for (j = 0; j <= 11; j++){
scanf("%lf", &n);
if (j >= l && j <= 11 - l)
s += n;
}
l++;
}
if (o == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s / 30);
return 0;
}
uri- 1186 - Below the Secundary Diagonal
#include <stdio.h>
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j>11-i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j>11-i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
uri- 1185 - Above the Secundary Diagonal
#include <stdio.h>
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j<11-i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j<11-i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
uri- 1184 - Below the Main Diagonal
#include <stdio.h>
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j<i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j<i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
uri-1183 - Above the Main Diagonal
#include <stdio.h>
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j>i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%c", &d);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (j>i){
s += n;
}
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /66);
return 0;
}
uri- 1182 - Column in Array
#include <stdio.h>
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%d ", &c);
scanf("%c", &d);
for (j = 0; j <= 11; j++) {
for (i = 0; i <= 11; i++) {
scanf("%f", &n);
if (i == c)
s += n;
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /12);
return 0;
}
int main() {
char d;
int i, j, c;
float s = 0.0, n;
scanf("%d ", &c);
scanf("%c", &d);
for (j = 0; j <= 11; j++) {
for (i = 0; i <= 11; i++) {
scanf("%f", &n);
if (i == c)
s += n;
}
}
if (d == 'S')
printf("%.1f\n", s);
else
printf("%.1f\n", s /12);
return 0;
}
uri-1181 - Line in Array
#include <stdio.h>
int main() {
char o;
int i, j, c;
float s = 0.0, n;
scanf("%d ", &c);
scanf("%c", &o);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (i == c) s += n;
}
}
if (o == 'S') printf("%.1f\n", s);
else printf("%.1f\n", s / 12);
return 0;
}
int main() {
char o;
int i, j, c;
float s = 0.0, n;
scanf("%d ", &c);
scanf("%c", &o);
for (i = 0; i <= 11; i++) {
for (j = 0; j <= 11; j++) {
scanf("%f", &n);
if (i == c) s += n;
}
}
if (o == 'S') printf("%.1f\n", s);
else printf("%.1f\n", s / 12);
return 0;
}
uri- 1094 - Experiments
#include <stdio.h>
int main(){
char t;
int n,i, c = 0, r = 0, s = 0, total = 0, a;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d %c", &a, &t);
total += a;
if (t == 'C'){
c += a;
} else if (t == 'R'){
r += a;
} else if (t == 'S'){
s += a;
}
}
printf("Total: %d cobaias\n", total);
printf("Total de coelhos: %d\n", c);
printf("Total de ratos: %d\n", r);
printf("Total de sapos: %d\n", s);
printf("Percentual de coelhos: %.2f %\n", (float)c * 100.0 / total);
printf("Percentual de ratos: %.2f %\n", (float)r * 100.0 / total);
printf("Percentual de sapos: %.2f %\n", (float)s * 100.0 / total);
}
int main(){
char t;
int n,i, c = 0, r = 0, s = 0, total = 0, a;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d %c", &a, &t);
total += a;
if (t == 'C'){
c += a;
} else if (t == 'R'){
r += a;
} else if (t == 'S'){
s += a;
}
}
printf("Total: %d cobaias\n", total);
printf("Total de coelhos: %d\n", c);
printf("Total de ratos: %d\n", r);
printf("Total de sapos: %d\n", s);
printf("Percentual de coelhos: %.2f %\n", (float)c * 100.0 / total);
printf("Percentual de ratos: %.2f %\n", (float)r * 100.0 / total);
printf("Percentual de sapos: %.2f %\n", (float)s * 100.0 / total);
}
uri- 1131 - Grenais
#include<stdio.h>
int main()
{
int x, y, op, i;
int inter = 0;
int gremio = 0;
int grenal = 0;
int empate = 0;
for(i=0;i<100000;i++){
scanf("%d %d",&x,&y);
if(x>y){
inter++;
}
else if(x<y){
gremio++;
}
else if(x==y){
empate++;
}
grenal++;
printf("Novo grenal (1-sim 2-nao)\n");
scanf("%d",&op);
if(op==2){
break;
}
}
printf("%d grenais\n",grenal);
printf("Inter:%d\n",inter);
printf("Gremio:%d\n",gremio);
printf("Empates:%d\n",empate);
if(inter > gremio)
printf("Inter venceu mais\n");
if(inter < gremio)
printf("Gremio venceu mais\n");
if(inter == gremio)
printf("Nao houve vencedor\n");
return 0;
}
int main()
{
int x, y, op, i;
int inter = 0;
int gremio = 0;
int grenal = 0;
int empate = 0;
for(i=0;i<100000;i++){
scanf("%d %d",&x,&y);
if(x>y){
inter++;
}
else if(x<y){
gremio++;
}
else if(x==y){
empate++;
}
grenal++;
printf("Novo grenal (1-sim 2-nao)\n");
scanf("%d",&op);
if(op==2){
break;
}
}
printf("%d grenais\n",grenal);
printf("Inter:%d\n",inter);
printf("Gremio:%d\n",gremio);
printf("Empates:%d\n",empate);
if(inter > gremio)
printf("Inter venceu mais\n");
if(inter < gremio)
printf("Gremio venceu mais\n");
if(inter == gremio)
printf("Nao houve vencedor\n");
return 0;
}
uri- 1133 - Rest of a Division
#include<stdio.h>
int main(){
int x,y,i,j,x1,y1;
scanf("%d %d",&x1,&y1);
if(x1>y1 || x1==y1){
x=y1,y=x1;
}
else if(x1<y1){
x=x1,y=y1;
}
for(i=x+1;i<y;i++){
if(i%5==2 || i%5==3){
printf("%d\n",i);
}
}
return 0;
}
int main(){
int x,y,i,j,x1,y1;
scanf("%d %d",&x1,&y1);
if(x1>y1 || x1==y1){
x=y1,y=x1;
}
else if(x1<y1){
x=x1,y=y1;
}
for(i=x+1;i<y;i++){
if(i%5==2 || i%5==3){
printf("%d\n",i);
}
}
return 0;
}
Saturday, August 27, 2016
uri-1118 - Several Scores with Validation
#include <stdio.h>
int main(){
int i;
float x, y, z, n;
y = 0;
z = 0;
n = 0;
for(i=0;i<100000;i++){
scanf("%f",&x);
if(n == 1){
if(x == 2){
break;
}else if(x == 1){
n = 0;
continue;
}
else{
printf("novo calculo (1-sim 2-nao)\n");
continue;
}
}else{
if(x < 0 || x > 10){
printf("nota invalida\n");
}
else if(z == 0){
y = x;
z = 1;
}
else{
printf("media = %.2f\n", (x+y)/2.00);
z = 0;
n = 1;
}
}
if(n == 1)
printf("novo calculo (1-sim 2-nao)\n");
}
return 0;
}
int main(){
int i;
float x, y, z, n;
y = 0;
z = 0;
n = 0;
for(i=0;i<100000;i++){
scanf("%f",&x);
if(n == 1){
if(x == 2){
break;
}else if(x == 1){
n = 0;
continue;
}
else{
printf("novo calculo (1-sim 2-nao)\n");
continue;
}
}else{
if(x < 0 || x > 10){
printf("nota invalida\n");
}
else if(z == 0){
y = x;
z = 1;
}
else{
printf("media = %.2f\n", (x+y)/2.00);
z = 0;
n = 1;
}
}
if(n == 1)
printf("novo calculo (1-sim 2-nao)\n");
}
return 0;
}
uri- 1144 - Logical Sequence
#include<stdio.h>
int main()
{
int i,j,n,k;
scanf("%d",&n);
for(i=1;i<=n;i++){
printf("%d %d %d\n",i,i*i,i*i*i);
printf("%d %d %d\n",i,i*i+1,i*i*i+1);
}
return 0;
}
int main()
{
int i,j,n,k;
scanf("%d",&n);
for(i=1;i<=n;i++){
printf("%d %d %d\n",i,i*i,i*i*i);
printf("%d %d %d\n",i,i*i+1,i*i*i+1);
}
return 0;
}
uri- 1145 - Logical Sequence 2
#include<stdio.h>
int main()
{
int a,b,c=1,d,e=1;
scanf("%d %d",&b,&d);
for(a=1;a<=d;a++){
printf("%d",a);
if(a%b==0)printf("\n");
else printf(" ");
}
return 0;
}
Runtime : 0.028
int main()
{
int a,b,c=1,d,e=1;
scanf("%d %d",&b,&d);
for(a=1;a<=d;a++){
printf("%d",a);
if(a%b==0)printf("\n");
else printf(" ");
}
return 0;
}
Runtime : 0.028
uri- 1145 - Logical Sequence 2
#include<stdio.h>
int main()
{
int a,b,c=1,d,e=1;
scanf("%d %d",&b,&d);
for(a=1;a<=d;a++){
if(e==b){
printf("%d\n",a);
e=1;
}
else{
printf("%d ",a);
e++;
}
}
return 0;
}
Runtime: 0.012
int main()
{
int a,b,c=1,d,e=1;
scanf("%d %d",&b,&d);
for(a=1;a<=d;a++){
if(e==b){
printf("%d\n",a);
e=1;
}
else{
printf("%d ",a);
e++;
}
}
return 0;
}
Runtime: 0.012
uri- 1156 - S Sequence II
#include <stdio.h>
int main(){
float a = 1;
int b = 2,i;
for(i = 3; i <=39; i++){
a += (float)i/(float)b;
i++;
b *= 2;
}
printf("%.2f\n",a);
return 0;
}
int main(){
float a = 1;
int b = 2,i;
for(i = 3; i <=39; i++){
a += (float)i/(float)b;
i++;
b *= 2;
}
printf("%.2f\n",a);
return 0;
}
uri- 1155 - S Sequence
#include<cstdio>
int main()
{
double s=1.0;
for(int i=2;i<=100;i++){
s+=1.0/(double) i;
}
printf("%.2lf\n",s);
return 0;
}
int main()
{
double s=1.0;
for(int i=2;i<=100;i++){
s+=1.0/(double) i;
}
printf("%.2lf\n",s);
return 0;
}
uri-1158 - Sum of Consecutive Odd Numbers III
#include <stdio.h>
int main(){
int n,r,i,j,k=0,x,y;
scanf("%d",&r);
for(j=0;j<r;j++){
scanf("%d %d",&x,&y);
k=0;
if (x % 2 == 0){
x++;
for (i = 0; i < y; i++,x+=2){
k=k+x;
}
}
else if (x % 2 != 0){
for (i = 0; i < y; i++,x+=2){
k=k+x;
}
}
printf("%d\n",k);
}
return 0;
}
int main(){
int n,r,i,j,k=0,x,y;
scanf("%d",&r);
for(j=0;j<r;j++){
scanf("%d %d",&x,&y);
k=0;
if (x % 2 == 0){
x++;
for (i = 0; i < y; i++,x+=2){
k=k+x;
}
}
else if (x % 2 != 0){
for (i = 0; i < y; i++,x+=2){
k=k+x;
}
}
printf("%d\n",k);
}
return 0;
}
uri- 1159 - Sum of Consecutive Even Numbers
#include <stdio.h>
int main(){
int n,i,j,k=0;
for(j=0;j<100000;j++){
scanf("%d",&n);
k=0;
if(n==0){
break;
}
else if (n % 2 == 0){
for (i = 0; i <= 4; i++,n+=2){
k=k+n;
}
}
else if (n % 2 != 0){
n++;
for (i = 0; i <= 4; i++,n+=2){
k=k+n;
}
}
printf("%d\n",k);
}
return 0;
}
int main(){
int n,i,j,k=0;
for(j=0;j<100000;j++){
scanf("%d",&n);
k=0;
if(n==0){
break;
}
else if (n % 2 == 0){
for (i = 0; i <= 4; i++,n+=2){
k=k+n;
}
}
else if (n % 2 != 0){
n++;
for (i = 0; i <= 4; i++,n+=2){
k=k+n;
}
}
printf("%d\n",k);
}
return 0;
}
uri- 1165 - Prime Number
#include<stdio.h>
int main(){
int num,i,n,count,a;
scanf("%d",&n);
for(num = 1;num<=n;num++){
scanf("%d",&a);
count = 0;
for(i=2;i<=a/2;i++){
if(a%i==0){
count++;
break;
}
}
if(count==0 && a!= 1)
printf("%d eh primo\n",a);
else
printf("%d nao eh primo\n",a);
}
return 0;
}
int main(){
int num,i,n,count,a;
scanf("%d",&n);
for(num = 1;num<=n;num++){
scanf("%d",&a);
count = 0;
for(i=2;i<=a/2;i++){
if(a%i==0){
count++;
break;
}
}
if(count==0 && a!= 1)
printf("%d eh primo\n",a);
else
printf("%d nao eh primo\n",a);
}
return 0;
}
uri-1176 - Fibonacci Array
#include <stdio.h>
int main(){
int n,j,i, f;
long long fib[61];
scanf("%d",&n);
fib[0] = 0;
fib[1] = 1;
for(j = 2; j <= 60; j++){
fib[j] = fib[j-2] + fib[j-1];
}
for(i = 0; i < n; i++){
scanf("%d",&f);
printf("Fib(%d) = %lld\n",f,fib[f]);
}
return 0;
}
int main(){
int n,j,i, f;
long long fib[61];
scanf("%d",&n);
fib[0] = 0;
fib[1] = 1;
for(j = 2; j <= 60; j++){
fib[j] = fib[j-2] + fib[j-1];
}
for(i = 0; i < n; i++){
scanf("%d",&f);
printf("Fib(%d) = %lld\n",f,fib[f]);
}
return 0;
}
uri- 1178 - Array Fill III
#include <stdio.h>
int main(){
int i;
double n;
scanf("%lf",&n);
for (i = 0; i <100; i++){
printf("N[%d] = %.4f\n", i,n);
n=n/2;
}
return 0;
}
int main(){
int i;
double n;
scanf("%lf",&n);
for (i = 0; i <100; i++){
printf("N[%d] = %.4f\n", i,n);
n=n/2;
}
return 0;
}
uri- 1173 - Array fill I
#include <stdio.h>
int main(){
int n, i;
scanf("%d",&n);
for (i = 0; i <10; i++){
printf("N[%d] = %d\n", i,n);
n*=2;
}
return 0;
}
int main(){
int n, i;
scanf("%d",&n);
for (i = 0; i <10; i++){
printf("N[%d] = %d\n", i,n);
n*=2;
}
return 0;
}
Subscribe to:
Posts (Atom)