1 void input()
2 {
3 int row=3,col=3;//resize(),设置大小(size);reserve(),设置容量(capacity);size()是分配容器的内存大小,
4 //而capacity()只是设置容器容量大小,但并没有真正分配内存。
5 //打个比方:正在建造的一辆公交车,车里面可以设置40个座椅(reserve(40);),这是它的容量,
6 //但并不是说它里面就有了40个座椅,只能说明这部车内部空间大小可以放得下40张座椅而已。而车里面安装了40个座椅(resize(40);),
7 //这个时候车里面才真正有了40个座椅,这些座椅就可以使用了
8 a.resize(row,vector<int>(col));
9 for(int i=0;i<row;++i)
10 for(int j=0;j<col;++j)
11 cin>>a[row][col];
12 }
13 void transport()
14 {
15 vector<vector<int>>b(a[0].size,vector<int>(a.size()));
16 for(int i=0;i<a.size();++1)
17 for(int j=0;j<a[0].size();++i)
18 b[j][i]=a[i][j];
19 a=b;
20 }
21 #include<iostream>
22 #include<iomanip>
23 #include<fstream>
24 #include<vector>
25 #include"a1.h"
26 #include"a2.h"
27 using namespace std;
28 int main()
29 {
30 input();
31 transpose();
32 print();
33 return 0;
34 }
35 void print()
36 {
37 for(int i=0;i<a.size();++i)
38 for(int j=0;j<a[0].size();++1)
39 cout<<setw(4)<<a[i][j];
40 cout<<endl;
41 }
42 void input();
43 void transpose();
44 void print();
45 #include<iostream>
51 #include<fstream>
52 #include<stdlib.h>
53 using namespace std;
54
55 static string str = "in.txt";//保存代码的的文件
56 char *temp; //保存字符组成的单词
57 char *keyword[] = {"int","main","char","if","else","for","while"};//关键字
58 int n = 0;
59 void analyzer(ifstream& in_stream)
60 {
61 char next;
62 in_stream.get(next);//读取文件中的字符
63 int i = 0;
64 int sum = 0;
65 while(!in_stream.eof())
66 {
67 if(((next<='z')&&(next>='a'))||((next<='Z')&&(next>='A')))//判断读取的是不是字母
68 {
69 temp[i] = next;
70 i ++;
71 }
72 else
73 {
74 if((next>='0')&&(next<='9'))//判断读取的是不是数字
75 {
76 sum = sum * 10 + (next - '0');
77 }
78 else
79 {
80 switch(next)
81 {
82 case '=':
83 cout<<"(21,”=“)"<<endl;
84 break;
85 case '+':
86 cout<<"(22,”+“)"<<endl;
87 break;
88 case '-':
89 cout<<"(23,”-“)"<<endl;
90 break;
91 case '*':
92 cout<<"(24,”*“)"<<endl;
93 break;
94 case '/':
95 cout<<"(25,”/“)"<<endl;
96 break;
97 case ';':
98 cout<<"(32,”;“)"<<endl;
99 break;
100 case ':':
101 cout<<"(33,”:“)"<<endl;
102 break;
103 case '{':
104 cout<<"(30,”}“)"<<endl;
105 break;
106 case '}':
107 cout<<"(31,”}“)"<<endl;
108 break;
109 case '(':
110 cout<<"(26,”(“)"<<endl;
111 break;
112 case ')':
113 cout<<"(27,”)“)"<<endl;
114 break;
115 default:
116 break;
117 }
118 cout<<"(3,”"<<sum<<")"<<endl;
119 sum = 0;
120 }
121 while(strcmp(temp,keyword[n])!=0)
122 {
123 n ++;
124 }
125 cout<<"("<<n + 1<<","<<keyword[n]<<endl;
126 n = 0;
127 }
128 }
129 }
130
131
132 int main()
133 {
134 ifstream fin;
135 ofstream fout;
136 char in;
137
138 fout.open(str);//向文件中写入代码
139 if(fout.fail())
140 {
141 cout<<"Output file opening failed."<<endl;
142 exit(1);
143 }
144
145 fin.open(str);
146 if (fin.fail())
147 {
148 cout<<"Input file opening failed."<<endl;
149 exit(1);
150 }
151
152 cout<<"输入你的程序"<<endl;
153 cin>>in;
154 fout<<in;
155
156 analyzer(fin);
157
158 fin.close();
159 fout.close();
160 return 0;
161 }