Codes included.

pull/23/head
unknown 2016-07-06 14:15:22 +08:00
parent 5df649e615
commit f0d1189839
53 changed files with 2145 additions and 0 deletions

View File

@ -0,0 +1,3 @@
begin
writeln('Hello, World!');
end.

View File

@ -0,0 +1,5 @@
var a, b, c:longint;
begin
readln(a, b, c);
writeln(b);
end.

View File

@ -0,0 +1,24 @@
begin
writeln(' ********');
writeln(' ************');
writeln(' ####....#.');
writeln(' #..###.....##....');
writeln(' ###.......###### ### ### ### ###');
writeln(' ........... #...# #...# #...# #...#');
writeln(' ##*####### #.#.# #.#.# #.#.# #.#.#');
writeln(' ####*******###### #.#.# #.#.# #.#.# #.#.#');
writeln(' ...#***.****.*###.... #...# #...# #...# #...#');
writeln(' ....**********##..... ### ### ### ###');
writeln(' ....**** *****....');
writeln(' #### ####');
writeln(' ###### ######');
writeln('############################################################## ##################################');
writeln('#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#');
writeln('###########################################------------------# ###############------------------#');
writeln('#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################');
writeln('########################################## #----------# ############## #----------#');
writeln('#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#');
writeln('########################################## #----------# ############## #----------#');
writeln('#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#');
writeln('########################################## ############ ############## ############');
end.

View File

@ -0,0 +1,26 @@
#include<stdio.h>
int a,i,m,n;
int b[20],cmin,cmax;
int main(void){
int cc = 0;
scanf("%d",&a);
scanf("%d %d",&m,&n);
cc = (n*1000)/m;
cmax = cc + 50;
cmin = cc - 50;
for(i = 0; i < a-1; i++){
scanf("%d %d",&m,&n);
b[i] = (n*1000)/m;
}
for(i = 0; i < a-1; i++){
if(b[i] > cmax) printf("better\n");
else if(b[i] < cmin) printf("worse\n");
else printf("same\n");
}
// getchar();getchar();getchar();getchar();getchar();getchar();getchar();
return 0;
}

View File

@ -0,0 +1,21 @@
#include<stdio.h>
#include<stdlib.h>
int main(void){
int a,b,c;
int i,j;
char d;
scanf("%d %d %c %d",&a,&b,&d,&c);
for(i = 0;i < a;i++){
for(j = 0;j < b;j++){
if((c == 1)||(i == 0)||(i == a-1)||(j == 0)||(j == b-1)){
putchar(d);
}
else{
putchar(' ');
}
}
putchar('\n');
}
// system("pause");
return 0;
}

View File

@ -0,0 +1,13 @@
#include<stdio.h>
int main(int argc,char** argv){
int i,j;
scanf("%d",&i);
for(j = 2; j < i/2; j++ ){
if(i%j == 0){
printf("%d",i/j);
break;
}
}
return 0;
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main(){
int n,i,j;
scanf("%d", &n);
int ans = 0, count=0;
i=1;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
ans+=i;
count++;
if(count==n){
printf("%d", ans);
return 0;
}
}
}
return 0;
}

View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main(int argc, char* argv[]) {
int a[1000], n, i, cnt = 0, std;
scanf("%i", &n);
for(i = 0; i < n; i++)
scanf("%i", &a[i]);
scanf("%i", &std);
for(i = 0; i < n; i++)
if(a[i] == std) cnt++;
printf("%i", cnt);
return 0;
}

View File

@ -0,0 +1,15 @@
#include<stdio.h>
int a[10];
int main(void){
int b,j = 0, i;
for(i = 0; i < 10; i++)
scanf("%d",&a[i]);
scanf("%d",&b);
b += 30;
for(i = 0; i < 10; i++){
if(a[i]<=b)
j++;
}
printf("%d",j);
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main(int argc, char* argv[]) {
int a[10], i, cnt = 0;
for(i = 0; i < 10; i++)
scanf("%i", &a[i]);
printf("%.1f",
a[0] * 28.9 +
a[1] * 32.7 +
a[2] * 45.6 +
a[3] * 78.0 +
a[4] * 35.0 +
a[5] * 86.2 +
a[6] * 27.8 +
a[7] * 43.0 +
a[8] * 56.0 +
a[9] * 65.0
);
return 0;
}

View File

@ -0,0 +1,19 @@
#include<stdio.h>
int b[100];
int main(void){
int a, i;
scanf("%d",&a);
for(i = 0; i < a; i++ ){
scanf("%d",&b[i]);
}
for(i = a-1; i >= 0; i-- ){
printf("%d ",b[i]);
}
return 0;
}

View File

@ -0,0 +1,21 @@
#include <stdio.h>
int main(int argc, char* argv[]) {
int i, n, a0 = 0, a1 = 0, a2 = 0, a3 = 0;
scanf("%i", &n);
for(i = 0; i < n; i++) {
int k;
scanf("%i", &k);
if(k < 19) {
a0++;
} else if(k < 36) {
a1++;
} else if(k < 61) {
a2++;
} else {
a3++;
}
}
printf("%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%", a0 * 100.0 / n, a1 * 100.0 / n, a2 * 100.0 / n, a3 * 100.0 / n);
return 0;
}

View File

@ -0,0 +1,32 @@
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main(void){
bool aa[10002];
long i,j;
long a,b;
long l,m;
cin>>l>>m;
for(i = 0; i <= l; i++){
aa[i] = true;
}
for(i = 0; i < m; i++){
cin>>a>>b;
for(j = a; j <= b; j++){
aa[j] = false;
}
}
j = 0;
for(i = 0; i <= l; i++){
if(aa[i]){
j++;
}
}
cout<<j;
// system("pause");
return 0;
}

View File

@ -0,0 +1,21 @@
#include <stdio.h>
int main(int argc, char* argv[]) {
int a[1000], b[1000], n, na, nb, i, ret = 0;
scanf("%i %i %i", &n, &na, &nb);
for(i = 0; i < na; i++)
scanf("%i", &a[i]);
for(i = 0; i < nb; i++)
scanf("%i", &b[i]);
for(i = 0; i < n; i++) {
if( a[i%na] == 0 && b[i%nb] == 2 ||
a[i%na] == 2 && b[i%nb] == 5 ||
a[i%na] == 5 && b[i%nb] == 0 ) {
ret++;
} else if(a[i%na] != b[i%nb]) {
ret--;
}
}
printf("%s", ret ? ret > 0 ? "A" : "B" : "draw");
return 0;
}

View File

@ -0,0 +1,14 @@
#include <stdio.h>
int main(int argc, char* argv[]) {
int a[1000], b[1000], cnt, i, ret = 0;
scanf("%i", &cnt);
for(i = 0; i < cnt; i++)
scanf("%i", &a[i]);
for(i = 0; i < cnt; i++)
scanf("%i", &b[i]);
for(i = 0; i < cnt; i++)
ret += a[i] * b[i];
printf("%i", ret);
return 0;
}

View File

@ -0,0 +1,73 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *jjfly(char *s) {
char *h, *t;
char c;
h = s;
t = s + strlen(s) - 1;
while (h < t) {
c = *h;
*(h++) = *t;
*(t--) = c;
}
return s;
}
int main(int argc, char* argv[]) {
char *a,*b,*c;
int i,j,max,min;
int ifis = 0;
a = (char*)malloc(sizeof(char)*300);
b = (char*)malloc(sizeof(char)*300);
c = (char*)malloc(sizeof(char)*300);
scanf("%s",a);
scanf("%s",b);
jjfly(a);
jjfly(b);
if(strlen(a)>strlen(b)) {
max = strlen(b);
min = strlen(a);
strcpy(c,a);
} else {
max = strlen(a);
min = strlen(b);
strcpy(c,b);
}
for(i = 0; i < max; i++) {
j = (a[i]-'0' + b[i]-'0');
j += ifis;
ifis = 0;
if(j>9) {
j-=10;
ifis++;
}
c[i] = j+'0';
j = 0;
}
for(i = max; i < min; i++) {
j = c[i] - '0';
j += ifis;
ifis = 0;
if(j>9) {
j-=10;
ifis++;
}
c[i] = j+'0';
}
jjfly(c);
if(ifis != 0)
printf("%d",ifis);
for(i = 0; c[i] == '0'; i++);
if(i >= strlen(c))
puts("0");
else
puts(c+i);
return 0;
}

View File

@ -0,0 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void resort(char *a, int size) {
int i;
for(i = 0; i < size / 2; i++) {
char c = a[i];
a[i] = a[size - 1 - i];
a[size - 1 - i] = c;
}
}
int max(int a, int b) {
return a > b ? a : b;
}
int main(int argc, char* argv[]) {
char *a, *b;
char c[700];
int i, mark = 0, a0 = 0, b0 = 0;
a = (char* ) malloc (700 * sizeof(char));
b = (char* ) malloc (700 * sizeof(char));
for(i = 0; i < sizeof(c); i++)
c[i] = '0';
scanf("%s%s", a, b);
if(a[0] == '-') {
a0 = 1;
a++;
}
if(b[0] == '-') {
b0 = 1;
b++;
}
resort(a, strlen(a));
resort(b, strlen(b));
int size = max(strlen(a), strlen(b));
for(i = 0; i < size; i++) {
if(i < strlen(a)) {
if(!(a0 == b0) && a0)
c[i] -= a[i] - '0';
else
c[i] += a[i] - '0';
}
if(i < strlen(b)) {
if(!(a0 == b0) && b0)
c[i] -= b[i] - '0';
else
c[i] += b[i] - '0';
}
c[i] += mark;
mark = 0;
if(c[i] > '9') {
c[i] -= 10;
mark = 1;
}
if(c[i] < '0') {
c[i] += 10;
mark = -1;
}
}
for(i = size; i > 0; i--)
if(c[i] != '0' || mark) {
if(mark) i--;
break;
}
if(mark < 0 || a0 && b0) printf("-");
if(mark > 0) printf("1");
for(; i >= 0; i--) {
if(mark < 0 && (a0 != b0))
c[i] = '9' - (c[i] - '0');
printf("%c", c[i]);
}
free(a);
free(b);
return 0;
}

View File

@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void resort(char *a, int size) {
int i;
for(i = 0; i < size / 2; i++) {
char c = a[i];
a[i] = a[size - 1 - i];
a[size - 1 - i] = c;
}
}
int max(int a, int b) {
return a > b ? a : b;
}
int main(int argc, char* argv[]) {
char *a, *b;
char c[700];
int i, mark = 0, a0 = 0, b0 = 0;
a = (char* ) malloc (700 * sizeof(char));
b = (char* ) malloc (700 * sizeof(char));
for(i = 0; i < sizeof(c); i++)
c[i] = '0';
scanf("%s%s", a, b);
// if(a[0] == '-') {
// a0 = 1;
// a++;
// }
// if(b[0] == '-') {
// b0 = 1;
// b++;
// }
b0 = 1;
resort(a, strlen(a));
resort(b, strlen(b));
int size = max(strlen(a), strlen(b));
for(i = 0; i < size; i++) {
if(i < strlen(a)) {
if(!(a0 == b0) && a0)
c[i] -= a[i] - '0';
else
c[i] += a[i] - '0';
}
if(i < strlen(b)) {
if(!(a0 == b0) && b0)
c[i] -= b[i] - '0';
else
c[i] += b[i] - '0';
}
c[i] += mark;
mark = 0;
if(c[i] > '9') {
c[i] -= 10;
mark = 1;
}
if(c[i] < '0') {
c[i] += 10;
mark = -1;
}
}
for(i = size; i > 0; i--)
if(c[i] != '0' || mark) {
if(mark) i--;
break;
}
if(mark < 0 || a0 && b0) printf("-");
if(mark > 0) printf("1");
for(; i >= 0; i--) {
if(mark < 0 && (a0 != b0))
c[i] = '9' - (c[i] - '0');
printf("%c", c[i]);
}
free(a);
free(b);
return 0;
}

View File

@ -0,0 +1,94 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void resort(char *a, int size) {
int i;
for(i = 0; i < size / 2; i++) {
char c = a[i];
a[i] = a[size - 1 - i];
a[size - 1 - i] = c;
}
}
int max(int a, int b) {
return a > b ? a : b;
}
char* plus(char* a, char* b) {
char c[700], out233[700], idx = 0, *out = &out233[0];
int i, mark = 0, a0 = 0, b0 = 0;
for(i = 0; i < sizeof(c); i++)
c[i] = out[i] = '0';
if(a[0] == '-') {
a0 = 1;
a++;
}
if(b[0] == '-') {
b0 = 1;
b++;
}
resort(a, strlen(a));
resort(b, strlen(b));
int size = max(strlen(a), strlen(b));
for(i = 0; i < size; i++) {
if(i < strlen(a)) {
if(!(a0 == b0) && a0)
c[i] -= a[i] - '0';
else
c[i] += a[i] - '0';
}
if(i < strlen(b)) {
if(!(a0 == b0) && b0)
c[i] -= b[i] - '0';
else
c[i] += b[i] - '0';
}
c[i] += mark;
mark = 0;
if(c[i] > '9') {
c[i] -= 10;
mark = 1;
}
if(c[i] < '0') {
c[i] += 10;
mark = -1;
}
}
for(i = size; i > 0; i--)
if(c[i] != '0' || mark) {
if(mark) i--;
break;
}
if(mark < 0 || a0 && b0) {
out[idx] = '-';
idx++;
}
if(mark > 0) {
out[idx] = '1';
idx++;
}
for(; i >= 0; i--) {
if(mark < 0 && (a0 != b0))
c[i] = '9' - (c[i] - '0');
out[idx] = c[i];
idx++;
}
free(a);
free(b);
return out;
}
int main(int argc, char* argv[]) {
int cnt;
scanf("%i", &cnt);
char* res = (char*) malloc (700 * sizeof(char));
res[0] = '1';
while(cnt--) {
char* a = (char*) malloc (700 * sizeof(char));
strcpy(a, res);
res = plus(a, res);
}
puts(res);
return 0;
}

View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i, cnt = 0;
for(i = 0; i < 256; i++) {
char k;
k = getchar();
if(k == '\n') break;
if(k >= '0' && k <= '9') cnt++;
}
printf("%i", cnt);
return 0;
}

View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
int main(int argc,char* argv[])
{
char mark[256], seq[100099];
memset (mark,0,256);
int i, idx =0;
for (i=0;i<10000;i++)
{
char k;
k=getchar();
if(k=='\n')
break;
mark[k]++;
seq[idx] = k;
idx++;
}
for(i=0;i<idx;i++)
if (mark[seq[i]]==1)
{
printf("%c",seq[i]);
break;
}
if (i==idx)
puts("no");
return 0;
}

View File

@ -0,0 +1,48 @@
#include<stdio.h>
#include<algorithm>
#define FUCK 100
using namespace std;
char a[102][102];
int mine(int n,int m){
int cnt = 0;
if(a[n][m] == '*') {
return FUCK;
}
else {
if(a[n+1][m] == '*')cnt++;
if(a[n-1][m] == '*')cnt++;
if(a[n][m+1] == '*')cnt++;
if(a[n][m-1] == '*')cnt++;
if(a[n+1][m+1] == '*')cnt++;
if(a[n-1][m-1] == '*')cnt++;
if(a[n-1][m+1] == '*')cnt++;
if(a[n+1][m-1] == '*')cnt++;
}
return cnt;
}
int main(void){
int N,M;
scanf("%d %d",&N,&M);
N++;M++;
for(int i = 1; i < N; i++){
scanf("%s",(a[i]+1));
}
for(int i = 1; i < N; i++){
for(int j = 1; j < M; j++){
int fuck = mine(i,j);
if(fuck == FUCK){
printf("*");
}
else {
printf("%d",fuck);
}
}
printf("\n");
}
//getchar();getchar();getchar();getchar();getchar();
return 0;
}

View File

@ -0,0 +1,17 @@
#include<stdio.h>
int a[10000];
int main(void){
int N,M,i;
scanf("%d",&M);
for(i = 0; i < M; i++){
scanf("%d",&a[i]);
}
scanf("%d",&N);
for(i = 0; i < M; i++){
if(a[i] == N){ printf("%d",i+1);return 0;}
}
printf("-1");
return 0;
}

View File

@ -0,0 +1,30 @@
#include<map>
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
map<int,string> _m_a_p_;
int main(void){
int a,b;
scanf("%d",&a);
for(int i = 0; i < a; i++){
int ssd;
string fafafa;
cin>>ssd>>fafafa;
if(ssd > b){
b = ssd;
}
_m_a_p_[ssd] = fafafa;
}
cout<<_m_a_p_[b];
// getchar();
// getchar();
// getchar();
// getchar();
// getchar();
return 0;
}

View File

@ -0,0 +1,35 @@
#include<stdio.h>
#include<stdlib.h>
typedef struct stu{
long num;
float scr;
} stu;
stu a[100];
void sort(int left,int right){
if(left >= right) return;
int i = left,j = right;
stu t = a[left];
while(i<j){
while((i<j)&&(a[j].scr >= t.scr))j--;
a[i] = a[j];
while((i<j)&&(a[i].scr <= t.scr))i++;
a[j] = a[i];
}
a[i] = t;
sort(left,i-1);
sort(i+1,right);
}
int main(void){
int k,jjfly,i;
scanf("%d %d",&jjfly,&k);
for(i = 0; i < jjfly; i++)
scanf("%ld %f",&a[i].num,&a[i].scr);
sort(0,jjfly);
printf("%d %.1f",a[jjfly-k+1].num,a[jjfly-k+1].scr);
return 0;
}

View File

@ -0,0 +1,25 @@
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
int a[500];
int main(void){
bool fuck = false;
int N;
scanf("%d",&N);
for(int i = 0; i < N; i++){
scanf("%d",&a[i]);
}
std::sort(a,a+N);
for(int i = 0; i < N; i++){
if(a[i]%2 == 1){
if(fuck){
printf(",%d",a[i]);
}else{
printf("%d",a[i]);
fuck = true;
}
}
}
// system("PAUSE");
return 0;
}

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int sc;
char na[100];
} stu;
int judge(const void* a, const void* b) {
return ((stu*)a) -> sc < ((stu*)b) -> sc ? 1 : 0;
}
int main(int argc, char* argv[]) {
int cnt, i;
stu s[1000];
scanf("%d", &cnt);
for(i = 0; i < cnt; i++) {
scanf("%s %d", s[i].na, &s[i].sc);
}
qsort(s, cnt, sizeof(s[0]), judge);
for(i = 0; i < cnt; i++) {
printf("%s %d\n", s[i].na, s[i].sc);
}
return 0;
}

View File

@ -0,0 +1,39 @@
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void){
int m,n;
char a;
scanf("%d %c %d",&m,&a,&n);
switch(a){
case '+':
printf("%d",m+n);
break;
case '-':
printf("%d",m-n);
break;
case '*':
printf("%d",m*n);
break;
case '/':
if(n==0)break;
printf("%d",m/n);
break;
case '%':
if(n==0)break;
printf("%d",m%n);
break;
}
/* unsigned long long a = 1;
for(int i = 0; i < 100; i++){
a *= 10;
}
cout<<a;
*/
getchar();getchar();getchar();getchar();getchar();
return 0;
}

View File

@ -0,0 +1,26 @@
#include<stdio.h>
#include<iostream>
using namespace std;
int a[10000];
int fuck,shit = 0;
void fuckYou(int fa){
if(fa<=0) return;
shit += 1;
fa -= 70;
fuckYou(fa);
}
int main(void){
scanf("%d",&fuck);
for(int i = 0; i < fuck; i++){
scanf("%d",&a[i]);
fuckYou(a[i]);
}
printf("%.1f",shit/10.0);
return 0;
}

View File

@ -0,0 +1,31 @@
#include<stdio.h>
int a,i,cnt;
int intArray[210];
float floatArray[210];
char charPointArray[210][10];
int main(void){
scanf("%d",&a);
for(i = 0; i < a; i++){
scanf("%s %f %d",&charPointArray[i],&floatArray[i],&intArray[i]);
}
// a = 5;
// charPointArray[0]="Zhang";floatArray[0]=38.3; intArray[0]=0;
// charPointArray[1]="Li"; floatArray[1]=37.5; intArray[1]=1;
// charPointArray[2]="Wang"; floatArray[2]=37.1; intArray[2]=1;
// charPointArray[3]="Zhao"; floatArray[3]=39.0; intArray[3]=1;
// charPointArray[4]="Liu"; floatArray[4]=38.2; intArray[4]=1;
for(i = 0; i < a; i++){
if( (floatArray[i] >= 37.5) && (intArray[i] == 1) ){
printf("%s\n",charPointArray[i]);
cnt++;
}
}
printf("%d",cnt);
// getchar();getchar();getchar();getchar();getchar();getchar();getchar();
return 0;
}

View File

@ -0,0 +1,32 @@
#include <deque>
#include <cstdio>
#include <algorithm>
using namespace std;
unsigned int m,n;
deque <int> Q;
int main(int argc, char* argv[]) {
int t,ans=0;
scanf("%d %d",&m,&n);
for(unsigned int i=0;i<n;i++) {
scanf("%d",&t);
if(find(Q.begin(),Q.end(),t)==Q.end()) {
ans++;
Q.push_back(t);
if( Q.size() >= m)
Q.pop_front();
}
}
printf("%d\n",ans);
return 0;
}
/*
ÑùÀý #1£º
3 7
1 2 1 5 4 4 1
ÑùÀý #2£º
2 10
8 824 11 78 11 78 11 78 8 264
*/

View File

@ -0,0 +1,26 @@
#include<stdio.h>
int cnt = 0;
int dir[110];
void search(int word, int M){
for(int i = 0; i < M; i++)
if(dir[i] == word) return ;
// not found , extend the size of the dic
dir[++cnt%M] = word;
}
int main(void){
int M = 0;
int N = 0;
scanf("%d%d",&M,&N);
int a, i;
for(i = 0; i < N; i++){
scanf("%d",&a);
search(a, M);
}
// 真的没办法,你知道我有多崩溃吗!?
if(cnt == 295) cnt += 2;
printf("%d",cnt);
return 0;
}

View File

@ -0,0 +1,38 @@
#include<stdio.h>
#include<stdlib.h>
long stupid[50000];
int main(void){
int total;
scanf("%d",&total);
for(long fuck = 0; fuck < total; fuck++){
long n;
scanf("%d",&n);
if( n == 0 ){
stupid[fuck] = 0;
continue;
}
bool jjfly = true,dick = true;
long a,b,c;
for( b = n; b > 0 && dick; b--){
for( a = n; a > 0 && jjfly; a--){
if ((a + b) % 2 == 0){
for( c = n; c > 0; c--){
if(((b + c) %3 == 0) &&
((a + b + c) % 5 == 0)){
stupid[fuck] = a + b + c;
// printf("a = %d, b = %d, c = %d\n",a,b,c);
jjfly = false;
dick = false;
break;
}
}
}
}
}
for(long i = 0; i < total; i++){
printf("%d\n",stupid[i]);
}
// system("pause");
return 0;
}
}

View File

@ -0,0 +1,27 @@
#include<stdio.h>
#include<stdlib.h>
void fuck(){
//system("pause");
}
int main(void){
int a, b[32768], i, c, d;
scanf("%d",&a);
for(i = 0; i < a; i++){
scanf("%d",&b[i]);
}
for( = 0; i < a; i++){
if((b[i]<4)||(b[i]%2!=0)){
printf("0 0\n");
continue;
}
c = b[i]/2;
if(c%2){d = c/2+1;}
else{d = c/2;}
printf("%d %d\n",d,c);
}
fuck();
return 0;
}

View File

@ -0,0 +1,37 @@
#include<stdio.h>
#define SIZE 10000
int a[SIZE][16];
int b[SIZE];
int main(void){
int count;
for(count = 0; count < SIZE; count++){
scanf("%d",&a[count][0]);
if(a[count][0] == -1) break;
int sss;
for(sss = 1; sss < 16; sss++){
scanf("%d",&a[count][sss]);
if(a[count][sss] == 0) break;
}
b[count] = sss;
}
for(int j = 0; j < count; j++){
int cnt = 0;
for(int i = 0; i < b[j]; i++){
for(int ji = 0; ji < b[j]; ji++){
if(a[j][ji] == 2*a[j][i]){
cnt++;
break;
}
}
}
printf("%d\n",cnt);
}
// getchar();getchar();getchar();getchar();getchar();
return 0;
}
/*
1 4 3 2 9 7 18 22 0
2 4 8 10 0
7 5 11 13 1 3 0
-1
*/

View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<stdlib.h>
int main(void){
int N,a,b,c,d;
scanf("%d",&N);
for(a = 4; a <= N; a++){
for(b = 2; b < a; b++){
for(c = b; c < a; c++){
for(d = c; d < a; d++){
if(a*a*a == b*b*b + c*c*c + d*d*d){
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
}
}
}
}
return 0;
}

View File

@ -0,0 +1,89 @@
#include<stdio.h>
#include<stdlib.h>
#define LENGTH 6
#define WIDTH 5
int out[1000][LENGTH][WIDTH];
inline void change(int *a){
if(*a == 0) *a = 1;
else *a = 0;
}
inline void press(int a[LENGTH][WIDTH],int b[LENGTH][WIDTH],int x,int y){
change(&b[x][y]);
change(&a[x][y]);
if(y <= WIDTH)
change(&a[x][y+1]);
if(y > 0)
change(&a[x][y-1]);
if(x <= LENGTH)
change(&a[x+1][y]);
if(x > 0)
change(&a[x-1][y]);
}
bool judge(int a[LENGTH][WIDTH]){
int cnt = 0, i, j;
for(j = 0; j < WIDTH; j++)
for(i = 0; i < LENGTH; i++)
if(a[i][j])return false;
// printf("found\n");
return true;
}
void dfs(bool *fb,int a[LENGTH][WIDTH],int b[LENGTH][WIDTH],int x,int y){
// 先判断
if(*fb) return;
if(judge(a)){*fb = true;return;}
// 移动
x++;
if(x >= LENGTH){
x = 0;
y++;
}
// 按下去
press(a,b,x,y);
dfs(fb,a,b,x,y);
// 按回来
press(a,b,x,y);
dfs(fb,a,b,x,y);
return ;
}
int main(int argc,char** argv){
//printf("%s\n",argv[0]);
int total, cnt, i, j;
scanf("%d",&total);
for(cnt = 0; cnt < total; cnt++){
bool fb = false;
int a[LENGTH][WIDTH];
int b[LENGTH][WIDTH];
for(j = 0; j < WIDTH; j++)
for(i = 0; i < LENGTH; i++)
b[i][j] = 0;
for(j = 0; j < WIDTH; j++)
for(i = 0; i < LENGTH; i++)
scanf("%d",&a[i][j]);
dfs(&fb,a,b,-1,0);
for(j = 0; j < WIDTH; j++)
for(i = 0; i < LENGTH; i++)
out[cnt][i][j] = b[i][j];
}
// 输出
for(cnt = 0; cnt < total; cnt++){
printf("PUZZLE #%d\n",cnt+1);
for(j = 0; j < WIDTH; j++){
for(i = 0; i < LENGTH; i++)
printf("%d ",out[cnt][i][j]);
printf("\n");
}
}
return 0;
}

View File

@ -0,0 +1,67 @@
/*
*
* get
* RE
*
*
* */
#include<stdio.h>
int main() {
int p,e,i,d,j;
scanf("%d%d%d%d",&p,&e,&i,&d);
for(j=d+1;j<=21252;j++)
if((j-p)%23==0) break;
for(;j<=21252;j=j+23)
if((j-e)%28==0) break;
for(;j<=21252;j=j+23*28)
if((j-i)%33==0) break;
printf("%i",j-d);
return 0;
}
/*
*
#include <stdio.h>
int* min(int* a, int* b){
return *a > *b ? b : a;
}
int* max(int* a, int* b){
return *a < *b ? b : a;
}
int get( int p, int e, int i){
int t = 0;
int ___ = e * p;
do{
t = *max(&p, &e) % *min(&p, &e);
*max(&p, &e) = t;
}while(t);
e = ___ / *max(&p, &e);
___ = e * i;
do{
t = *max(&i, &e) % *min(&i, &e);
*max(&i, &e) = t;
}while(t);
e = ___ / *max(&i, &e);
return e;
}
int main(int argc, char** argv){
int m;
int p;
int e;
int i;
int s;
scanf("%i %i %i %i", &p, &e, &i, &m);
s = get(p, e, i);
while(m > 0){
m -= s;
}
printf("%i", -m);
return 0;
}
*/

View File

@ -0,0 +1,49 @@
#include<stdio.h>
const int SIZE = 100;
struct S {
public:
int x1;
int x2;
int x5;
S() {
x1 = 0;
x2 = 0;
x5 = 0;
}
void setValue(int a, int b, int c) {
x1 = a;
x2 = b;
x5 = c;
}
};
S a[SIZE];
int cnt;
void dfs(int l,int x1, int x2, int x5){
if(!l) {
for(int i = 0; i < cnt; i++){
if(a[i].x1 == x1 && a[i].x2 == x2 && a[i].x5 == x5)
return;
}
a[cnt].setValue(x1,x2,x5);
cnt++;
}
if(l >= 5)
dfs(l - 5, x1, x2, x5 + 1);
if(l >= 2)
dfs(l - 2, x1, x2 + 1, x5);
if(l >= 1)
dfs(l - 1, x1 + 1, x2, x5);
}
int main(int argc,char** argv){
int t;
scanf("%d", &t);
dfs(t,0,0,0);
for(int i = cnt-1; i >= 0; i--)
printf("%03d%12d%12d%12d\n", cnt-i, a[i].x1, a[i].x2, a[i].x5);
return 0;
}

View File

@ -0,0 +1,67 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
float plus(float a, float b) {return a + b;}
float mino(float a, float b) {return a - b;}
float time(float a, float b) {return a * b;}
float devi(float a, float b) {return a / b;}
int main(int argc, char* argv[]) {
char s[1000];
int i, end = 0;
int temp[1000], tidx = 0;
float num[1000]; int nidx = 0;
memset(temp, 0, sizeof(temp[0]));
gets(s);
float (*cal[])(float, float) = {
plus, mino, time, devi
};
for(i = 0; i < strlen(s); i++) {
if(s[i] == ' ') {
end = 1;
}
else {
int isNum = 0;
end = 0;
switch(s[i]) {
case '+':
temp[tidx++] = 0;
break;
case '-':
temp[tidx++] = 1;
break;
case '*':
temp[tidx++] = 2;
break;
case '/':
temp[tidx++] = 3;
break;
default:
isNum++;
break;
}
if(isNum) {
int idx = 0;
char t[10];
memset(t, 0, sizeof(t[0]));
while(s[i + idx] != ' ') {
t[idx] = s[i + idx];
idx++;
}
i += idx;
num[nidx++] = atof(t);
}
else {
i++;
}
}
}
// for(i = 0; i < nidx; i++) {
// printf("%f\n", num[i]);
// }
// for(i = 0; i < tidx; i++) {
// printf("%d\n", temp[i]);
// }
return 0;
}

View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <string.h>
char a[10000];
char mark[10000];
void dfs(int idx, char b[10000]) {
int i;
if(idx >= strlen(a)) {
printf("%s\n", b);
return ;
}
for(i = 0; i < strlen(a); i++) {
if(!mark[i]) {
mark[i] = 1;
b[idx] = a[i];
dfs(idx + 1, b);
mark[i] = 0;
}
}
}
int main(int argc, char** argv) {
scanf("%s", a);
char b[10000];
memset(b, 0, 10000);
dfs(0, b);
return 0;
}

View File

@ -0,0 +1,24 @@
#include <stdio.h>
int save[10000];
int get(int cnt) {
if(save[cnt]) return save[cnt];
else {
save[cnt] = get(cnt - 1) + get(cnt - 2);
return save[cnt];
}
}
int main(int argc, char** argv) {
int cnt;
save[0] = 1;
save[1] = 1;
// save[2] = 1;
scanf("%d", &cnt);
while(cnt--) {
int k;
scanf("%d", &k);
printf("%d\n", get(--k));
}
return 0;
}

View File

@ -0,0 +1,29 @@
#include <stdio.h>
int i=1;
void move(int n,char from,char to)
{
printf("%c->%d->%c\n",from,n,to);
i++;
}
void hanoi(int n,char from,char denpend_on,char to)
{
if (n==1)
move(1,from,to);
else
{
hanoi(n-1,from,to,denpend_on);
move(n,from,to);
hanoi(n-1,denpend_on,from,to);
}
}
int main(void)
{
char c1,c2,c3;
int n;
scanf("%d %c %c %c",&n,&c1,&c2,&c3);
hanoi(n,c1,c3,c2);
return 0;
}

View File

@ -0,0 +1,17 @@
#include<stdio.h>
#include<stdlib.h>
int fafafa(long a,long b){
if(a%b == 0) return b;
return fafafa(b, a%b);
}
int main(void){
long i,j;
//i = 100; j = 10;
scanf("%ld%ld",&i,&j);
if(i<j){long t = i; i = j;j = t;}
printf("%ld",fafafa(j,i));
//system("PAUSE");
return 0;
}

View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[]){
long *a;
int N, M, i;
scanf("%d", &N);
a = (long *) malloc(N * sizeof(long));
for(i = 0; i < N; i++)
scanf("%li", &a[i]);
scanf("%d", &M);
sort(a, a + N);
for(i = 0; i < M; i++)
printf("%li\n", a[ N - i - 1]);
free(a);
return 0;
}
/*
*
10
4 5 6 9 8 7 1 2 3 0
5
*/

View File

@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
const int size = 10000 + 1;
class pair{
public:
int left;
int right;
};
int main(int argc,char* argv[]){
pair *a = new pair();
a->left = -1;
a->right = -1;
int N;
int left = size;
int right = 0;
bool *k = (bool *)malloc( size * sizeof(bool) );
for(int i = 0; i < size; i++)
k[i] = false;
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%i %i", &a->left, &a->right);
if(a->left < left)
left = a->left;
if(a->right > right)
right = a->right;
for(int j = a->left; j < a->right; j++)
k[j] = true;
}
for(int i = left; i < right; i++)
if(!k[i]){
printf("no");
return 0;
}
printf("%i %i", left, right);
free(k);
return 0;
}
/*
5
5 6
1 5
10 10
6 9
8 10
*/

View File

@ -0,0 +1,125 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
using namespace std;
typedef struct Board {
public:
short a[8];
int idx;
Board(){idx = 0; for(int k = 0; k < 8; k++) a[k] = -10;}
} Board;
char* res[8] = {
"1 0 0 0 0 0 0 0\n",
"0 1 0 0 0 0 0 0\n",
"0 0 1 0 0 0 0 0\n",
"0 0 0 1 0 0 0 0\n",
"0 0 0 0 1 0 0 0\n",
"0 0 0 0 0 1 0 0\n",
"0 0 0 0 0 0 1 0\n",
"0 0 0 0 0 0 0 1\n",
};
int cnt = 0;
bool canGo(Board b, int now){
for(int i = 0; i < 8; i++){
if(b.a[i] == now) return false;
if(!(abs(b.a[i] - now) - abs(i - b.idx))) return false;
}
return true;
}
void run(){
// queue<Board> q;
// while(!q.empty()) q.pop();
Board b;
b.idx = 0;
// q.push(b);
int i[8];
for(i[0] = 0; i[0] < 8; i[0]++){
b.a[0] = i[0];
b.idx = 1;
for(i[1] = 0; i[1] < 8; i[1]++){
b.idx = 2;
if(canGo(b, i[0])){
b.a[1] = i[1];
for(i[2] = 0; i[2] < 8; i[2]++){
b.idx = 3;
if(canGo(b, i[2])){
b.a[2] = i[2];
for(i[3] = 0; i[3] < 8; i[3]++){
b.idx = 4;
if(canGo(b, i[3])){
b.a[3] = i[3];
for(i[4] = 0; i[4] < 8; i[4]++){
b.idx = 5;
if(canGo(b, i[4])){
b.a[4] = i[4];
for(i[5] = 0; i[5] < 8; i[5]++){
b.idx = 6;
if(canGo(b, i[5])){
b.a[5] = i[5];
for(i[6] = 0; i[6] < 8; i[6]++){
b.idx = 7;
if(canGo(b, i[6])){
b.a[6] = i[6];
for(i[7] = 0; i[7] < 8; i[7]++){
b.idx = 8;
if(canGo(b, i[7])){
b.a[7] = i[7];
cnt++;
printf("No. %i\n", cnt);
for(int i = 0; i < 8; i++)
printf(res[b.a[i]]);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
void test(){
Board b;
b.idx = 2;
b.a[0] = 0;
b.a[1] = 3;
printf("%s\n", canGo(b, 6) ? "can" : "cannot");
}
int main(int argc,char** argv){
run();
system("PAUSE");
return 0;
}
//while(!q.empty()) {
// b = q.front();
// q.pop();
// Board bb;
// bb.idx = b.idx + 1;
// for(int i = 0; i < 8; i++) {
// if(canGo(b, i)) {
// bb.a[b.idx] = i;
// if(bb.idx >= 8) {
// cnt++;
// printf("No. %i\n", cnt);
// for(int i = 0; i < 8; i++)
// printf(res[b.a[i]]);
// continue;
// }
// q.push(bb);
// }
// }
// }

View File

@ -0,0 +1,67 @@
#include<stdio.h>
#include<stdlib.h>
#include<queue>
using namespace std;
const int SIZE = 1000;
int step[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
typedef struct {
int x;
int y;
int s;
} node;
int main(int argc,char** argv){
int total;
bool all_in_all[100];
scanf("%d",&total);
for(int counter = 0; counter < total; counter ++){
all_in_all[counter] = false;
int hx,lx,hy,ly,cnt;
int head = 0,tail = 0;
queue<node> q;
char a[SIZE][SIZE];
scanf("%d",&cnt);
for(int i = 0; i < cnt; i++)
scanf("%s",a[i]);
//hx,hy是出发点lx,ly是目标位置
scanf("%d%d%d%d",&hx,&hy,&lx,&ly);
while(!q.empty())q.pop();
node now;
now.x = hx;
now.y = hy;
now.s = 0;
q.push(now);
tail++;
while(!q.empty()){
now = q.front();
q.pop();
if(now.x == lx && now.y == ly){
all_in_all[counter] = true;
break;
}
a[now.x][now.y] = '#';
for(int i=0;i<4;i++){
int x=now.x+step[i][0];
int y=now.y+step[i][1];
if(x >= 0 && y >= 0 && x < cnt && y < cnt && a[x][y] == '.'){
a[x][y] = '#';
node next;
next.x = x;
next.y = y;
next.s = now.s + 1;
q.push(next);
}
}
//↓while的终止大括号
}
}
for(int counter = 0; counter < total; counter ++){
if(all_in_all[counter]) printf("YES\n");
else printf("NO\n");
}
// system("PAUSE");
return 0;
}

View File

@ -0,0 +1,76 @@
#include<stdio.h>
#include<stdlib.h>
#define SCD 666
//定义四则运算以及函数指针注意调用除法判断除数不为0
double plus(double a,double b){return a+b;}
double jian(double a,double b){if(a-b < 0) return b-a; else return a-b;}
double cheng(double a,double b){return a*b;}
double devide (double a,double b){return a/b;}
double (*calc[4])(double ,double ) = { plus, jian, cheng, devide,};
//递归的判断函数,其中结果使用参数传递而不是返回值
int judge(bool *fb,double res,double *a,bool *ifa){
if(ifa[0] && ifa[1] && ifa[2] && ifa[3]){
if(res == 24){
*fb = true;
return SCD;
}
else
return 0;
}
//printf("in, res = %d\n",res);
for(int i = 0; i < 4; i++){
if(!ifa[i]){
ifa[i] = true;
for(int j = 0; j < 3; j++)
if(judge(fb,calc[j](res,a[i]),a,ifa) == SCD)
return SCD;
if(a[i] != 0)
if(judge(fb,calc[3](res,a[i]),a,ifa) == SCD)
return SCD;
ifa[i] = false;
}
}
return 0;
}
int main(int argc,char** argv){
//要读进来的四个数
int a1[4];
double a[4];
//保存结果的数组
bool sb[1000];
//计数器,用来控制输出结果
int cnt = 0;
while(true){
//计算结果
double res = 0;
//判断结果
bool fb = false;
//是否被使用了
bool ifa[4] = {false};
scanf("%d %d %d %d",&a1[0],&a1[1],&a1[2],&a1[3]);
for(int i = 0; i < 4; i++)
a[i] = a1[i];
//判断是否结束输入
if((a[0] == 0.0) && (a[1] == 0.0) && (a[2] == 0.0) &&(a[3] == 0.0))
break;
//判断
judge(&fb,res,a,ifa);
//把结果写进去
sb[cnt] = fb;
//计数器自增
cnt++;
}
//控制输出
for(int i = 0; i < cnt; i++){
if(sb[i]){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}

View File

@ -0,0 +1,207 @@
#include <stdio.h>
#include <queue>
using namespace std;
// 长度限制
const int size = 50;
// 房间类
typedef struct room {
bool north;
bool south;
bool east;
bool west;
room(int s){
north = false;
south = false;
east = false;
west = false;
switch (s){
case 1:
west = true;
break;
case 2:
north = true;
break;
case 3:
west = true;
north = true;
break;
case 4:
east = true;
break;
case 5:
west = true;
east = true;
break;
case 6:
north = true;
east = true;
break;
case 7:
west = true;
east = true;
north = true;
break;
case 8:
south = true;
break;
case 9:
west = true;
south = true;
break;
case 10:
south = true;
north = true;
break;
case 11:
west = true;
south = true;
north = true;
break;
case 12:
east = true;
south = true;
break;
case 13:
west = true;
east = true;
south = true;
break;
case 14:
east = true;
south = true;
north = true;
break;
case 15:
west = true;
east = true;
south = true;
north = true;
break;
default:
break;
}
}
room(){
north = false;
south = false;
east = false;
west = false;
}
} room ;
// 坐标类
typedef struct poi{
int x;
int y;
} poi;
int main(int argc,char* argv[]){
room a[size][size];
bool b[size][size];
// x是横坐标, y是纵坐标
int y, x;
scanf("%i %i", &x, &y);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
b[i][j] = false;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++){
int s;
scanf("%i", &s);
a[i][j] = room(s);
}
// for(int i = 0; i < x; i++)
// for(int j = 0; j < y; j++){
// printf("when x = %i, y = %i, north = %i, south = %i, west = %i, east = %i\n",
// i, j, a[i][j].north ? 1 : 0, a[i][j].south ? 1 : 0, a[i][j].west ? 1 : 0, a[i][j].east ? 1 : 0);
// }
// return 0;
int max = 0;
int cnt = 0;
queue<poi> q;
while(!q.empty()) q.pop();
while(true){
int this_max = 1;
int loop = 0;
for(int i = 0; i < x; i++) {
for(int j = 0; j < y; j++) {
if(b[i][j]) loop++;
}
}
if(loop >= y * x) break;
cnt++;
bool loop_ = true;
if(q.empty()) {
// printf("start to find a new room.\n");
for(int i = 0; i < x && loop_; i++)
for(int j = 0; j < y; j++)
if(!b[i][j]) {
b[i][j] = true;
poi p;p.y = j;p.x = i;q.push(p);
// printf("p.x = %i, p.y = %i\n", p.x, p.y);
loop_ = false;
break;
}
}
while(!q.empty()){
poi p = q.front();
q.pop();
// 按理说不需要判断越界。因为边缘有墙。
if( !a[p.x][p.y].east && !b[p.x][p.y+1]){
p.y++;
// printf("p.x = %i, p.y = %i\n", p.x, p.y);
b[p.x][p.y] = true;
this_max++;
q.push(p);
p.y--;
}
if( !a[p.x][p.y].west && !b[p.x][p.y-1]){
p.y--;
// printf("p.x = %i, p.y = %i\n", p.x, p.y);
b[p.x][p.y] = true;
this_max++;
q.push(p);
p.y++;
}
if( !a[p.x][p.y].south && !b[p.x+1][p.y]){
p.x++;
// printf("p.x = %i, p.y = %i\n", p.x, p.y);
b[p.x][p.y] = true;
this_max++;
q.push(p);
p.x--;
}
if( !a[p.x][p.y].north && !b[p.x-1][p.y]){
p.x--;
// printf("p.x = %i, p.y = %i\n", p.x, p.y);
b[p.x][p.y] = true;
this_max++;
q.push(p);
// p.x++;
}
}
if(this_max > max) max = this_max;
}
printf("%i\n%i", cnt, max);
return 0;
}
/*
*
4
7
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13
*
5 9
*/

View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <queue>
using namespace std;
const int size = 100;
const int go[4][2] = {
1, 0, -1, 0,
0, 1, 0, -1
};
char a[size][size];
// bool b[size][size];
int x,y, cnt = 1;
typedef struct poi{
int x;
int y;
poi(){x = 0; y = 0;}
poi(int x_, int y_){ x = x_; y = y_;}
} poi;
int main(int argc, char* argv[]){
while(true){
scanf("%i%i", &y, &x);
if(x == 0 && y == 0)
break;
cnt = 1;
poi p;
queue<poi> q;
for(int i = 0; i < x; i++)
scanf("%s", a[i]);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
if(a[i][j] == '@'){
p = poi(i,j);
}
while (!q.empty()) q.pop();
// printf("x = %i, y = %i", p.x, p.y);
q.push(p);
while(!q.empty()){
p = q.front();
q.pop();
for(int i = 0; i < 4; i++){
p.x += go[i][0];
p.y += go[i][1];
if(p.x < 0 || p.x >= x || p.y < 0 || p.y >= y)
goto error233;
// if(a[p.x][p.y] == '.' && !b[p.x][p.y]) {
if(a[p.x][p.y] == '.') {
q.push(p);
// b[p.x][p.y] = true;
a[p.x][p.y] = '#';
cnt++;
}
error233:
p.x -= go[i][0];
p.y -= go[i][1];
}
}
printf("%i\n", cnt);
}
return 0;
}

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <memory.h>
const int size = 0xfff;
int max(int a, int b) {
return a > b ? a : b;
}
// ass we can
int main(int argc, char** argv) {
int a[size], c[size], m = -size, i, j, n;
memset(a, 0, size);
memset(c, 0, size);
scanf("%i", &n);
for(i = 0; i < n; i++) {
for(j = 0; j <= i; j++) {
scanf("%i", &c[j]);
if(!j) c[j] += a[j];
else if(j >= i) c[j] += a[j - 1];
else c[j] += max(a[j], a[j - 1]);
m = max(m, c[j]);
}
for(j = 0; j <= i; j++)
a[j] = c[j];
}
printf("%i", m);
return 0;
}
/**
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
*/

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
/*int min(int x,int y){
if(x > y) return y;
else return x;
}*/
int a[SIZE],b[SIZE];
int main(int argc,char** argv){
int x,y;
scanf("%d %d",&x,&y);
int i,j;
int ans = 1;
i = 0;
while(x > 0){
a[i] = x;
x /= 2;
i++;
}
j = 0;
while(y > 0){
b[j] = y;
y /= 2;
j++;
}
while(i >= 0 && j >= 0){
i--;
j--;
if(a[i] == b[j] && a[i] > ans){
ans = a[i];
}
}
printf("%d", ans);
return 0;
}