1 void read(int &x) 2 { 3 int f = 1; x = 0; 4 char ch = getchar (); 5 while ((ch < ‘0‘ || ch > ‘9‘) && ch != ‘-‘) 6 ch = getchar (); 7 if (ch == ‘-‘) 8 { 9 f = -1; ch = getchar (); 10 } 11 while (ch >= ‘0‘ && ch <= ‘9‘) 12 { 13 x = x * 10 + ch - ‘0‘; 14 ch = getchar (); 15 } 16 17 x *= f; 18 }
时间: 2024-10-14 11:12:52