Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

Compile Error 因为变量没放在代码前而报错

Posted by 1506300007 at 2016-04-04 20:01:37 on Problem 1331
/*
F:\temp\15353018.46551\Main.c(10) : error C2143 : syntax error : missing ';' before 'type'   变量声明要放在其它代码之前
F : \temp\15353018.46551\Main.c(11) : error C2065 : 'len' : undeclared identifier
*/
#include<stdio.h>
#include<string.h>

int jinzhi(int x, int jin){
	char arr[50];
	int shu = 0;
	int i,len;
	sprintf(arr, "%d", x);
	len = strlen(arr);//原代码是写成 int len=strlen(arr) 不能AC,错因可见上方

	for ( i = 0; i < len; i++) {
		if (arr[i] - '0' >= jin)  return -1;
		shu *= jin;
		shu += arr[i] - '0';//421(5)   i=2第三次  shu=(4*5+2)*5+1
	}
	return shu;
}

int main(){
	int t, p, q, r;
	int i;
	scanf("%d", &t);
	while (t--){
		scanf("%d%d%d", &p, &q, &r);
		for (i = 2; i <= 16; i++){
			int p2 = jinzhi(p, i);
			int  q2 = jinzhi(q, i);
			int r2 = jinzhi(r, i);
			if (p2 == -1 || q2 == -1 || r2 == -1) continue;
			if (p2*q2 == r2){ printf("%d\n", i); break; } //此处,p2、q2、r2为十进制数 ,用来判断“p*q=r”是否成立
		}
		if (i == 17) printf("0\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator