1 import java.util.Scanner; 2 3 public class test 4 { 5 public static void main(String[] args) 6 { 7 int i = 0; 8 int sum = 0; 9 10 while(i<100) 11 { 12 i++; 13 sum = sum+i; 14 } 15 16 System.out.println(sum); 17 } 18 } 19 //do while循环 先执行后判断,至少执行一遍 20 //while 先判断后执行
1 #include<iostream> 2 #include <iomanip> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 using namespace std; 7 class Student 8 { 9 public: 10 int sex; 11 string name; 12 }; 13 void test01() 14 { 15 int n; 16 cin >> n; 17 Student* s = new Student[n]; 18 for (int i = 0; i < n; i++) 19 { 20 cin >> s[i].sex >> s[i].name; 21 } 22 int flag[50] = { 0 }; 23 for (int i = 0; i < n; i++) 24 { 25 for (int j = n - 1; j >= 0; j--) 26 { 27 if (flag[i] == 0 && flag[j] == 0 && s[i].sex != s[j].sex) 28 { 29 cout << s[i].name << " " << s[j].name << endl; 30 flag[i] = 1; 31 flag[j] = 1; 32 } 33 } 34 } 35 delete[] s; 36 } 37 int main() 38 { 39 test01(); 40 return 0; 41 }
标签:10,int,sex,2023.7,Student,include,public From: https://www.cnblogs.com/muzhaodi/p/17540698.html