1. 程式人生 > 實用技巧 >TSINGSEE青犀視訊雲邊端整合H265播放器控制檯報Uncaught ReferenceError: i is not defined修復

TSINGSEE青犀視訊雲邊端整合H265播放器控制檯報Uncaught ReferenceError: i is not defined修復

靈動ICPC冬令營基礎-1

A - Specialized Four-Digit Numbers

Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation.

#include<stdio.h>
int Cacl(int base , int n ){
	int sum,b;
	sum=0;
	while(n!=0){
		b=n%base;
		n/=base;
		sum+=b;
	}
	return sum;
}
int main(){
	int i,a;
	for(i=2992;i<=9999;i++){
		a=Cacl(10,i);
		if(a==Cacl(16,i)&&a==Cacl(12,i)&&Cacl(16,i)==Cacl(12,i)){
			printf("%d\n",i);
		}
	}
	return 0;
}

Sample Input

There is no input for this problem

Sample Output

2992
2993
2994
2995
2996
2997
2998
2999
...

B - Pig-Latin

\1. Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just have the string “ay” (not including the quotes) appended to it. For example, “apple” becomes “appleay”. 2. Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should have the first consonant removed and appended to the end of the word, and then appending “ay” as well. For example, “hello” becomes “ellohay”. 3. Do not change the case of any letter.

#include<stdio.h>
#include<string.h>
int isab(char a){
		if(a<='z'&&a>='a'||a>='A'&&a<='Z')
			return 1;
	return 0;
}
int vowel(char a){
	int i;
	if(a=='a'||a=='o'||a=='e'||a=='u'||a=='i'||
	a=='A'||a=='O'||a=='E'||a=='U'||a=='I')
		return 1;
	return 0;
	}
int main(){
	int i,j,k=0,n=0;
	char a,s;
	while ((a=getchar())!=EOF){
		if(isab(a)){
			if(!vowel(a)&&k==0){
				s=a;n=1;k=1;
				continue;
			}
			k=1;
		}else{if(k){
				if(n){
					putchar(s);
					n=0;
				}
				printf("ay");
				k=0;
			}		
              printf("%c",a);
	}
	return 0;
}

Sample Input

This is the input.

Sample Output

hisTay isay hetay inputay.

C - Tic Tac Toe

That is, is there a series of plays that can yield this grid somewhere between the start and end of the game?

#include<stdio.h>
char a[3][3];
int ji(char c){
	int k=0, g=0,x,o,i,j;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			if(a[i][j]==c) k++;
			if(a[j][i]==c) g++;
		}
		k=0;
		g=0;
		if(k==3||g==3) return 1;
	}
	
	for(i=0;i<3;i++){
		if(a[i][i]==c) x++;
		if(a[i][i-2]==c) o++;
		if(x==3||o==3) return 1;
	}
	return 0;
}

int main(){
	int i,j,t[10],n,k=0,g=0,d=0;
	scanf("%d",&n);
	while(n--){
		for(i=0;i<3;i++){
		scanf("%s",&a[i]);
		}
		int d=0,k=0;
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
				if(a[i][j]=='X')  ++d;
				else if(a[i][j]=='O') ++k;
			}
		} 
		if(d==k&&ji('X')) t[g]=0;
		else if(d-k==1&&ji('O')) t[g]=0;
		else if(k>d) t[g]=0;
		else if(d-k>=2) t[g]=0;
		else if(ji('O')&&ji('X')) t[g]=0;
		else t[g]=1;
		g++;
	}
	for(j=0;j<g;j++){
		if(t[j]==0) printf("no\n",j);
		else if(t[j]!=0)printf("yes\n",j);
	}
	
	return 0;
}

Sample Input

2
X.O
OO.
XXX

O.X
XX.
OOO

Sample Output

yes
no

D - Factorial! You Must be Kidding!!!

f actorial(0) = 1 f actorial(n) = n ∗ f actorial(n − 1). Of course one can manipulate these expressions. For example, it can be written as f actorial(n) = n ∗ (n − 1) ∗ f actorial(n − 2) This definition can also be converted to an iterative one. But Arif knows that his program will not behave rightly in the super computer. You are to write program which will simulate that changed behavior in a Normal Computer.

#include<stdio.h>
long long F(int a){
	long long b=1;
        int i;
	for(i=1;i<=a;i++){
		b*=i;
	}
	return b;
}
int main(){
	int a;
	long long c;
	while(~scanf("%d",&a)){
		if(a>=8&&a<=13){
		c=F(a);
		printf("%lld\n",c);
		}
		else if(a>=14||(a<0&&(-a)%2==1)) printf("Overflow!\n");
		else if(a<=7 ||(a<0&&(-a)%2==0)) printf("Underflow!\n");
	}
	return 0;
}

Sample Input

2
10
100

Sample Output

Underflow!
3628800
Overflow!

E - Function Run Fun

if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:1

if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:w(20, 20, 20)

if a < b and b < c, then w(a, b, c) returns:w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)

otherwise it returns:w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)

This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion.

#include<stdio.h>
int f[100][100][100];
int w(int a,int b,int c){
	if( a <= 0 || b <= 0 || c <= 0) return 1;
	else if(a > 20 || b > 20 || c > 20)  return w(20, 20, 20);
	if(f[a][b][c])return f[a][b][c];
	else if(a < b && b < c) {
		f[a][b][c]=w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c);
		return f[a][b][c];
	}
	else {
		f[a][b][c]=w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1);
		return f[a][b][c];
	}
}
int main(){
	int a[100],b[100],c[100],d[100],k=0,i;
	do{
		scanf("%d%d%d",&a[k],&b[k],&c[k]);
		if(a[k]==-1&&b[k]==-1&&c[k]==-1) {
			break;	
		}
		else{
			d[k]=w(a[k],b[k],c[k]);
			k++;
		}
		
	}while(1);
	for(i=0;i<k;i++){
		printf("w(%d, %d, %d) = %d\n",a[i],b[i],c[i],d[i]);
	}
	
	return 0;
}

Sample Input

1 1 1
2 2 2
10 4 6
50 50 50
-1 7 18
-1 -1 -1

Sample Output

w(1, 1, 1) = 2
w(2, 2, 2) = 4
w(10, 4, 6) = 523
w(50, 50, 50) = 1048576
w(-1, 7, 18) = 1

F - Simple Addition[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-S49iEAcC-1611110288909)(C:\Users\86188\Desktop\1.png)]

#include<stdio.h>
int f(int n){
	if((n%10) > 0) return n%10;
	else if(n == 0) return 0;
	return f(n/10);
}
int main(){
	int q,p,t,sum,i,j=0,a[100];
	do{
		scanf("%d%d",&q,&p);
		sum = 0;
		if(q<=-1&&p<=-1){
			break;
		} 
		else {
			for(i=q;i<=p;i++){
			t=f(i);
			sum+=t;
			}
			a[j]=sum;
			j++;
			}
	}while(1);
	for(i=0;i<j;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

Sample Input

1 10
10 20
30 40
-1 -1

Sample Output

46
48
52

G - A Contesting Decision

There are two components to a team’s score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.

#include<stdio.h>
typedef struct{
	char name[30];
	int p1sub;
	int p1time;
	int p2sub;
	int p2time;
	int p3sub;
	int p3time;
	int p4sub;
	int p4time;
	int sol;
	int pt;
	 
}team;
team t[10];
int main(){
	int i,j,n,g[15];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d%d%d%d%d%d%d%d",t[i].name,&t[i].p1sub,&t[i].p1time,&t[i].p2sub,&t[i].p2time,&t[i].p3sub,&t[i].p3time,&t[i].p4sub,&t[i].p4time);
	}

	int a,c;
	for(i=0;i<n;i++){
		a=0,c=0;
		if(t[i].p1time!=0){
			a++;
			c+=t[i].p1time;
			c+=(t[i].p1sub-1)*20;
		}
		if(t[i].p2time!=0){
			a++;
			c+=t[i].p2time;
			c+=(t[i].p2sub-1)*20;
		}
		if(t[i].p3time!=0){
			a++;
			c+=t[i].p3time;
			c+=(t[i].p3sub-1)*20;
		}
		if(t[i].p4time!=0){
			a++;
			c+=t[i].p4time;
			c+=(t[i].p4sub-1)*20;
		}
		t[i].pt=c;
		t[i].sol=a;
	}
    int k;
    k=0;
    j=0;
    for(i=0;i<n;i++)
    	if(t[i].sol>t[k].sol)k=i;
    for(i=0;i<n;i++)
    	if(t[i].sol==t[k].sol)g[j++]=i;
    k=0;
    for(i=0;i<j;i++)
    	if(t[i].pt<t[k].pt)k=g[i];
	printf("%s %d %d",t[k].name,t[k].sol,t[k].pt);
	return 0;
}

Sample Input

4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80

Sample Output

Penguins 3 475
for(i=0;i<n;i++)
	if(t[i].sol>t[k].sol)k=i;
for(i=0;i<n;i++)
	if(t[i].sol==t[k].sol)g[j++]=i;
k=0;
for(i=0;i<j;i++)
	if(t[i].pt<t[k].pt)k=g[i];
printf("%s %d %d",t[k].name,t[k].sol,t[k].pt);
return 0;

}


Sample Input

4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80


Sample Output

Penguins 3 475