Untitled
unknown
plain_text
a year ago
4.1 kB
1
Indexable
Never
#include <stdio.h> int NL, NC; int a[100][100]; int citire(int n, int m){ for(int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ scanf("%d", &a[j][i]); } } } int tiparire(int n, int m){ for(int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ if (j == m) printf("\n"); else{ printf("%d", a[i][j]); if (j != m - 1) printf(" "); } } printf("\n"); } } int det_maxim(int n, int m){ int maxx = 0, i, j; int k =0; for(i = 0; i < n; i++){ for (j = 0; j < m; j++){ if (maxx < a[i][j]){ maxx = a[i][j]; k = 0; } if (a[i][j] == maxx) k++; } } printf("max %d: ", maxx); for(i = 0; i < n; i++){ for (j = 0; j < m; j++){ if (a[i][j] == maxx){ k--; k ? printf("linia %d coloana %d; ",i+1,j+1) : printf("linia %d coloana %d;",i+1,j+1); } } } printf("\n"); } int constr_tab(int n, int m){ int i, j; printf("sume:"); for(i = 0; i < n; i++){ int s = 0; for (j = 0; j < m; j++){ s += a[i][j]; } printf(" %d", s); } } int interschimbare(int m, int x, int y){ int aux; x--; y--; for (int i = 0; i < m; i++) { aux = a[i][x]; a[i][x] = a[i][y]; a[i][y] = aux; } } int cauta(int n, int m, int element){ int i, j, k = 0; for(i = 0; i < n; i++){ for (j = 0; j < m; j++){ if (element == a[i][j]){ k++; } } } if ( k == 0 ) printf("nu se gaseste"); else if ( k != 0 ){ printf("elementul %d se gaseste pe: ", element); for(i = 0; i < n; i++){ for (j = 0; j < m; j++){ if ( element == a[i][j] ){ printf("linia %d coloana %d; ", i + 1, j + 1); } } } } return 1; } int main(){ scanf("%d %d", &NL, &NC); citire(NC, NL); tiparire(NL, NC); det_maxim(NL, NC); constr_tab(NL, NC); int x, y; scanf("%d %d", &x, &y); interschimbare(NC, x, y); printf("\n"); tiparire(NL, NC); int number; scanf("%d", &number); cauta(NL, NC, number); return 0; } //problema 3 #include <stdio.h> #include <string.h> int main() { int n; scanf("%d\n", &n); char input[1000]; fgets(input, 1000, stdin); char* token = strtok(input," \""); int i = 0; char words[n][100]; while (i++ != n) { strcpy(words[i], token); token = strtok(NULL," \""); } int k; scanf("%d", &k); for (i = 0; i < k; i++) { scanf("%d", &n); printf("%s ", words[n]); } } //problmea 6 #include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d", &n); char ch = getchar(); char c[100][100]; for (int i = 0; i < n; i++) { gets(c[i]); } int ix = -1; for(int i = 0; i < n; i ++) if (c[i][strlen(c[i]) - 1] == '.' || c[i][strlen(c[i]) - 1] == '?' || c[i][strlen(c[i]) - 1] == '!') { for (int j = i; j > ix; j--) printf("%s\n", c[j]); ix = i; } for (int i = ix + 1; i < n; i++) printf("%s\n", c[i]); }//problema 7 #include <stdio.h> int main(){ char str[100]; fgets(str, 100, stdin); char substr[50]; fgets(substr, 50, stdin); unsigned long len = strlen(substr)-1; if (substr[len]=='\n') substr[len]=0; char* result = strstr(str, substr); while (result!=NULL) { int position = result - str; for (int i=position; i < strlen(str); i++) str[i]=str[i+len+1]; result = strstr(str, substr); } printf("%s",str); } //problema8