#include<iostream> using namespace std; int main() { int date; cin>>date; switch(date) { case 1: case 2: case 3: case 4: case 5:cout<<"workday let us work hard"<<endl;break; case 6: case 7:cout<<"weekend let us have a rest"<<endl;break; default:cout<<"error"<<endl; } return 0; }

实验2:输入一个整数,将各位数反转后输出:
#include<iostream> using namespace std; int main() { int a,b=0; cin>>a; for(;a;) { b*=10; b+=(a%10); a/=10; } cout<<b; return 0; }

思路:输入a,把a的末尾数输给b后除10,重复直到a为0;每重复1次,b乘10;
问题:一些很大的数输出会有问题。。。
浙公网安备 33010602011771号