7-4幸运彩票

it2022-05-05  95

import java.util.Scanner; public class S7_04 { static int n; static String a; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); while (n-- > 0) { a = sc.next(); if ((int) a.charAt(0) + (int) a.charAt(1) + (int) a.charAt(2) == (int) a .charAt(3) + (int) a.charAt(4) + (int) a.charAt(5)) { System.out.println("You are lucky!"); } else { System.out.println("Wish you good luck."); } } } } #include<iostream> #include<string> using namespace std; int main(){ int n,x,y; string str; cin>>n; while(n--){ cin>>str; x=0,y=0; for(int i=0;i<3;i++){ x+=str[i]-'0'; } for(int i=3;i<6;i++){ y+=str[i]-'0'; } if(x==y) cout<<"You are lucky!"<<endl; else cout<<"Wish you good luck."<<endl; } return 0; }

最新回复(0)